Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/skills/add-dotnet-aot-command/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ but inside that process the BCL "where am I" APIs do **not** point there:
So deriving an SDK-relative path (`MSBuild.dll`, `Sdks/`, `DotnetTools/`, targets) from
`AppContext.BaseDirectory` or a dll path is **wrong** in the AOT bubble. Instead:

- **In-repo:** read `SdkPaths.SdkDirectory` (in `Microsoft.DotNet.Cli.Utils`), which resolves the
- **In-repo:** read `SdkPaths.SdkDirectory` (in `Microsoft.DotNet.Cli.CoreUtils`), which resolves the
`Microsoft.DotNet.Sdk.Root` AppContext value -> SDK assembly directory -> `AppContext.BaseDirectory`
(once, cached).
- `NativeEntryPoint.ExecuteCore` resolves the SDK directory once (host `sdk_dir`, else self-locating the
Expand Down
4 changes: 1 addition & 3 deletions src/Cli/Microsoft.DotNet.Cli.CoreUtils/DotnetFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ namespace Microsoft.DotNet.Cli.Utils;

public static class DotnetFiles
{
private static string SdkRootFolder => AppContext.BaseDirectory;

private static readonly Lazy<DotnetVersionFile> s_versionFileObject =
new(() => new DotnetVersionFile(VersionFile));

/// <summary>
/// The SDK ships with a .version file that stores the commit information and SDK version
/// </summary>
public static string VersionFile => Path.GetFullPath(Path.Combine(SdkRootFolder, ".version"));
public static string VersionFile => Path.GetFullPath(Path.Combine(SdkPaths.SdkDirectory, ".version"));

public static DotnetVersionFile VersionFileObject => s_versionFileObject.Value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
<Nullable>enable</Nullable>
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="dotnet" />
<InternalsVisibleTo Include="dotnet-aot" />
<InternalsVisibleTo Include="dotnet-aot.Tests" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Cli.Utils;
/// <para>
/// Under the Native AOT CLI (<c>dotnet-aot</c> loaded directly by the muxer) the BCL location APIs do
/// NOT point at the versioned SDK directory: <see cref="System.AppContext.BaseDirectory"/> and
/// <see cref="System.Environment.ProcessPath"/> resolve to the install root (the muxer's own
/// <c>Environment.ProcessPath</c> resolve to the install root (the muxer's own
/// directory) and <c>Assembly.Location</c> is empty. The AOT entry point therefore publishes the
/// resolved SDK directory as the <c>Microsoft.DotNet.Sdk.Root</c> AppContext value, which this helper
/// reads first. Code that needs an SDK-relative path (MSBuild, tasks, tools, forwarders) should use
Expand Down Expand Up @@ -66,7 +66,7 @@ internal static string ResolveSdkDirectory()
return sdkRoot;
}

// The SDK assemblies ship in the versioned SDK directory, so the location of this assembly is that
// CoreUtils ships in the versioned SDK directory, so the location of this assembly is that
// directory for the JIT-compiled managed CLI. Under a single-file / NativeAOT deployment
// Assembly.Location is empty (which is what the IL3000 analyzer flags); fall through to
// AppContext.BaseDirectory in that case - the AOT bridge sets the AppContext value (preferred above).
Expand Down
9 changes: 9 additions & 0 deletions test/dotnet-aot.Tests/AotIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ private void RunSeparatedLayoutBasePathTest(bool selfLocate)
Directory.CreateDirectory(sdkSubDir);
try
{
// These are synthetic sentinel values; only their end-to-end appearance in --version matters.
const string expectedVersion = "11.0.100-preview.7.12345.67";
File.Copy(aotSource, Path.Combine(sdkSubDir, aotLib));
File.WriteAllLines(
Path.Combine(sdkSubDir, ".version"),
["0123456789abcdef", expectedVersion]);

var env = new Dictionary<string, string> { ["DOTNET_AOT_SDK_DIR"] = sdkSubDir };
if (selfLocate)
Expand All @@ -189,6 +194,10 @@ private void RunSeparatedLayoutBasePathTest(bool selfLocate)

Assert.IsTrue(basePathReferencesSdkDir,
$"--info Base Path did not reference the resolved SDK directory '{sdkSubDir}'. Output:\n{stdout}");

var (versionExitCode, versionOutput, _) = RunDn(["--version"], enableAot: true, extraEnv: env);
Assert.AreEqual(0, versionExitCode);
Assert.AreEqual(expectedVersion, versionOutput.Trim());
}
finally
{
Expand Down