Skip to content

Conversation

@dsplaisted
Copy link
Member

  • Implement GetSupportedChannels via release APIs and add test coverage
  • Remove unused mock classes
  • Fix issue where SDK path from global.json wasn't being resolved relative to the global.json file
  • Fix some NativeAOT issues

There were some NativeAOT issues with Microsoft.DotNet.NativeWrapper. I've fixed the warnings but I'm not sure how loading the hostfxr libraries is supposed to work in a NativeAOT app. The code expects to find hostfxr.dll in the app base directory. So we may need some more changes there.

There are also trim warnings from Spectre.Console which cause the NatievAOT publish to fail. However, I haven't yet figured out what those warnings actually are.

We should hook up a publish of dnup to the pipelines so that we are validating we can actually produce a NativeAOT app.

@baronfel
Copy link
Member

What do we need hostfxr for on this pathway? We will not have access to it at all in AOT mode IIRC, we may need to use something like the library @ericstj pointed me at earlier today to get a managed equivalent to what hostfxr provides.

@dsplaisted
Copy link
Member Author

What do we need hostfxr for on this pathway? We will not have access to it at all in AOT mode IIRC, we may need to use something like the library @ericstj pointed me at earlier today to get a managed equivalent to what hostfxr provides.

Right now we are using it to validate that an SDK or runtime has installed correctly:

private bool ValidateWithHostFxr(string installRoot, ReleaseVersion resolvedVersion, InstallComponent component)
{
try
{
ConfigureHostFxrResolution(installRoot);
var bundleProvider = new NETBundlesNativeWrapper();
NetEnvironmentInfo environmentInfo = bundleProvider.GetDotnetEnvironmentInfo(installRoot);
if (component == InstallComponent.SDK)
{
string expectedPath = Path.Combine(installRoot, "sdk", resolvedVersion.ToString());
return environmentInfo.SdkInfo.Any(sdk =>
string.Equals(sdk.Version.ToString(), resolvedVersion.ToString(), StringComparison.OrdinalIgnoreCase) &&
DnupUtilities.PathsEqual(sdk.Path, expectedPath));
}
if (!RuntimeMonikerByComponent.TryGetValue(component, out string? runtimeMoniker))
{
return false;
}
string expectedRuntimePath = Path.Combine(installRoot, "shared", runtimeMoniker, resolvedVersion.ToString());
return environmentInfo.RuntimeInfo.Any(runtime =>
string.Equals(runtime.Name, runtimeMoniker, StringComparison.OrdinalIgnoreCase) &&
string.Equals(runtime.Version.ToString(), resolvedVersion.ToString(), StringComparison.OrdinalIgnoreCase) &&
DnupUtilities.PathsEqual(runtime.Path, expectedRuntimePath));
}
catch
{
return false;
}
}

I think we were thinking about also using it to find what versions are installed.

@baronfel
Copy link
Member

Here's the library I mentioned: https://github.com/ericstj/dotnetlocator - it's not production but seems to be the way we're starting to think about this kind of shared resource.

I think its expected surface area would be able to satisfy what hostfxr is being used for in the code you linked?

Copy link
Member

@nagilson nagilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good call out on the AOT portion and the SDK tests not running dnup tests. I've left a few comments.

public IEnumerable<string> GetSupportedChannels()
{

return ["latest", "preview", "lts", "sts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep this in a data structure of special keyword channels we support.


<PropertyGroup>
<TargetFrameworks>$(ResolverTargetFramework);net472</TargetFrameworks>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my understanding, why did we use net8.0 here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I didn't have the condition it gave me an error saying the property wasn't supported for .NET Framework, and the error suggested this condition. I think the property is maybe supported on .NET 6 and higher.

for (var i = 0; i < (int)infoStruct.sdk_count; i++)
{
var pointer = new IntPtr(infoStruct.sdks.ToInt64() + i * Marshal.SizeOf(typeof(hostfxr_dotnet_environment_sdk_info)));
var pointer = new IntPtr(infoStruct.sdks.ToInt64() + i * Marshal.SizeOf<hostfxr_dotnet_environment_sdk_info>());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@dsplaisted dsplaisted merged commit 72f4fb4 into dotnet:release/dnup Oct 30, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants