Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RID regression by adding a task that calculates the best matching RID for platform #5695

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
14 changes: 14 additions & 0 deletions Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Redis.ApiService", "playgro
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Redis.AppHost", "playground\Redis\Redis.AppHost\Redis.AppHost.csproj", "{6249A193-3BF4-4FFB-AB81-6590A8318889}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Sdk.Tests", "tests\Aspire.Hosting.Sdk.Tests\Aspire.Hosting.Sdk.Tests.csproj", "{AEF07BC6-76D8-4A45-89D5-54FC4483863F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.RuntimeIdentifier.Tool", "src\Aspire.Hosting.Sdk\Aspire.RuntimeIdentifier.Tool\Aspire.RuntimeIdentifier.Tool.csproj", "{FF2895FC-A613-43DC-96B8-E5DFA69125CA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1622,6 +1626,14 @@ Global
{6249A193-3BF4-4FFB-AB81-6590A8318889}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6249A193-3BF4-4FFB-AB81-6590A8318889}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6249A193-3BF4-4FFB-AB81-6590A8318889}.Release|Any CPU.Build.0 = Release|Any CPU
{AEF07BC6-76D8-4A45-89D5-54FC4483863F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEF07BC6-76D8-4A45-89D5-54FC4483863F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEF07BC6-76D8-4A45-89D5-54FC4483863F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEF07BC6-76D8-4A45-89D5-54FC4483863F}.Release|Any CPU.Build.0 = Release|Any CPU
{FF2895FC-A613-43DC-96B8-E5DFA69125CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF2895FC-A613-43DC-96B8-E5DFA69125CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF2895FC-A613-43DC-96B8-E5DFA69125CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF2895FC-A613-43DC-96B8-E5DFA69125CA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1919,6 +1931,8 @@ Global
{874EA351-05EA-44F5-8B12-7A7F865ECEC5} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
{B4CB2D9D-D3F5-4BB1-A7C0-7A6F13316A78} = {874EA351-05EA-44F5-8B12-7A7F865ECEC5}
{6249A193-3BF4-4FFB-AB81-6590A8318889} = {874EA351-05EA-44F5-8B12-7A7F865ECEC5}
{AEF07BC6-76D8-4A45-89D5-54FC4483863F} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{FF2895FC-A613-43DC-96B8-E5DFA69125CA} = {F534D4F8-5E3A-42FC-BCD7-4C2D6060F9C8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}
Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
<PackageVersion Include="Microsoft.Extensions.Primitives" Version="$(MicrosoftExtensionsPrimitivesPackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="$(MicrosoftExtensionsHttpResiliencePackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="$(MicrosoftExtensionsTimeProviderTestingVersion)" />
<!-- NuGet dependencies -->
<PackageVersion Include="NuGet.ProjectModel" Version="6.11.0" />
<!-- external dependencies -->
<PackageVersion Include="Confluent.Kafka" Version="2.5.3" />
<PackageVersion Include="Dapper" Version="2.1.44" />
Expand Down
4 changes: 2 additions & 2 deletions eng/dashboardpack/Sdk.in.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<!-- *** BEGIN *** -->

<PropertyGroup Condition="'$(NETCoreSdkRuntimeIdentifier)' == '@PlatformRuntime@'">
<PropertyGroup>
joperezr marked this conversation as resolved.
Show resolved Hide resolved
<AspireDashboardDir Condition=" '$(AspireDashboardDir)' == '' ">$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', 'tools'))</AspireDashboardDir>
<AspireDashboardDir>$([MSBuild]::EnsureTrailingSlash('$(AspireDashboardDir)'))</AspireDashboardDir>
<AspireDashboardPath Condition=" '$(AspireDashboardPath)' == '' ">$([MSBuild]::NormalizePath($(AspireDashboardDir), 'Aspire.Dashboard'))</AspireDashboardPath>
<AspireDashboardPath Condition=" '$(OS)' == 'Windows_NT' and !$(AspireDashboardPath.EndsWith('.exe')) ">$(AspireDashboardPath).exe</AspireDashboardPath>
<AspireDashboardPath Condition="$([MSBuild]::IsOsPlatform('OSX')) and !$(AspireDashboardPath.EndsWith('.dll'))">$(AspireDashboardPath).dll</AspireDashboardPath>
</PropertyGroup>

<ItemGroup Condition="'$(NETCoreSdkRuntimeIdentifier)' == '@PlatformRuntime@'">
<ItemGroup>
<ProjectCapability Include="AspireDashboard" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion eng/dcppack/Aspire.Hosting.Orchestration.in.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>

<PropertyGroup Condition="'$(NETCoreSdkRuntimeIdentifier)' == '@PlatformRuntime@'">
<PropertyGroup>
joperezr marked this conversation as resolved.
Show resolved Hide resolved
<DcpDir Condition=" '$(DcpDir)' == '' ">$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', 'tools'))</DcpDir>
<DcpDir>$([MSBuild]::EnsureTrailingSlash('$(DcpDir)'))</DcpDir>
<DcpExtensionsDir Condition=" '$(DcpExtensionsDir)' == '' ">$([MSBuild]::NormalizeDirectory($(DcpDir), 'ext'))</DcpExtensionsDir>
Expand Down
28 changes: 28 additions & 0 deletions src/Aspire.Hosting.Sdk/Aspire.Hosting.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,45 @@
<PropertyGroup>
<PackageTags>aspire hosting sdk</PackageTags>
<Description>.NET Aspire Hosting SDK. Enabled via &lt;IsAspireHost&gt;true&lt;/IsAspireHost&gt;.</Description>
<TargetsForTfmSpecificContentInPackage>_PublishAndPackRIDTool;$(TargetsForTfmSpecificContentInPackage)</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>

<PropertyGroup>
<MinCodeCoverage>100</MinCodeCoverage>
</PropertyGroup>

<ItemGroup>
<TextReplacementValue Include="DefaultTargetFramework" NewValue="$(DefaultTargetFramework)" />
</ItemGroup>

<ItemGroup>
<None Include="..\Aspire.Hosting\build\*.targets" Link="SDK\%(Filename)%(Extension)" Pack="true" PackagePath="Sdk\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
<None Update="SDK\AutoImport.props;SDK\*.targets" Pack="true" PackagePath="Sdk\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
<None Update="SDK\Sdk.in.props" Pack="true" PerformTextReplacement="True" PackagePath="Sdk\Sdk.props" CopyToOutputDirectory="PreserveNewest" />
<None Update="SDK\Sdk.in.targets" Pack="true" PerformTextReplacement="True" PackagePath="Sdk\Sdk.targets" />

<!-- Adding a project reference to the tool to avoid MSBuild having clashes when building this project before the other. -->
<ProjectReference Include="Aspire.RuntimeIdentifier.Tool\Aspire.RuntimeIdentifier.Tool.csproj"
ReferenceOutputAssembly="false"
SkipTargetFrameworkProperties="true"
ExcludeAssets="all"
Private="false" />
</ItemGroup>

<Target Name="_PublishAndPackRIDTool">
<MSBuild Projects="$(MSBuildThisFileDirectory)Aspire.RuntimeIdentifier.Tool\Aspire.RuntimeIdentifier.Tool.csproj"
Targets="Publish"
Properties="Configuration=$(Configuration);Platform=$(Platform)" />

<ItemGroup>
<_publishContentToPackage Include="$(DotNetOutputPath)Aspire.RuntimeIdentifier.Tool/$(Configuration)/$(DefaultTargetFramework)/publish/**/*" />
</ItemGroup>

<ItemGroup>
<TfmSpecificPackageFile Include="@(_publishContentToPackage)"
PackagePath="tools/$(DefaultTargetFramework)/%(_publishContentToPackage.RecursiveDir)" />
</ItemGroup>

</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
Copy link
Member

Choose a reason for hiding this comment

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

Nesting .csprojs under folders that already contain a .csproj is typically not a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, though in this case the parent project is a NoTargets SDK project meaning it doesn't compile anything, and the child project doesn't have any targets that could be packed by the parent by accident either. Main reason why I made it a child project, is that the parent is the one that packs this. I could change it of course, but this "feels" better. There is also precedent in dotnet/runtime where source generator projects are nested under the package that packs them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

in dotnet/runtime, it is the src project that packs them, which is a sibling, not in a parent directory.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh -- fair enough. I don't feel strongly about this but I can change it if you want me to.


<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
<RollForward>Major</RollForward>
<UsePublicApiAnalyzers>false</UsePublicApiAnalyzers>
<IsPackable>false</IsPackable>
</PropertyGroup>
joperezr marked this conversation as resolved.
Show resolved Hide resolved

<ItemGroup>
<PackageReference Include="System.CommandLine" />
<PackageReference Include="NuGet.ProjectModel" />
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions src/Aspire.Hosting.Sdk/Aspire.RuntimeIdentifier.Tool/NuGetUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using NuGet.RuntimeModel;

namespace Aspire.Hosting.Sdk;

/*
* These utility methods were copied from the sdk repository to mimic the behavior used when selecting the best matching RID
* for a given runtime identifier. For more information, please see the original source code at:
* https://github.com/dotnet/sdk/blob/e6da8ca6de3ec8f392dc87b8529415e1ef59b7ea/src/Tasks/Microsoft.NET.Build.Tasks/NuGetUtils.NuGet.cs#L76-L109
*/

internal static class NuGetUtils
{
public static string? GetBestMatchingRid(RuntimeGraph runtimeGraph, string runtimeIdentifier,
IEnumerable<string> availableRuntimeIdentifiers, out bool wasInGraph)
{
return GetBestMatchingRidWithExclusion(runtimeGraph, runtimeIdentifier,
runtimeIdentifiersToExclude: null,
availableRuntimeIdentifiers, out wasInGraph);
}

public static string? GetBestMatchingRidWithExclusion(RuntimeGraph runtimeGraph, string runtimeIdentifier,
IEnumerable<string>? runtimeIdentifiersToExclude,
IEnumerable<string> availableRuntimeIdentifiers, out bool wasInGraph)
{
wasInGraph = runtimeGraph.Runtimes.ContainsKey(runtimeIdentifier);

string? bestMatch = null;

HashSet<string> availableRids = new(availableRuntimeIdentifiers, StringComparer.Ordinal);
HashSet<string>? excludedRids = runtimeIdentifiersToExclude switch { null => null, _ => new HashSet<string>(runtimeIdentifiersToExclude, StringComparer.Ordinal) };
foreach (var candidateRuntimeIdentifier in runtimeGraph.ExpandRuntime(runtimeIdentifier))
{
if (bestMatch == null && availableRids.Contains(candidateRuntimeIdentifier))
{
bestMatch = candidateRuntimeIdentifier;
}

if (excludedRids != null && excludedRids.Contains(candidateRuntimeIdentifier))
{
// Don't treat this as a match
return null;
}
}

return bestMatch;
}
}
88 changes: 88 additions & 0 deletions src/Aspire.Hosting.Sdk/Aspire.RuntimeIdentifier.Tool/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using System.CommandLine.Parsing;
using System.Diagnostics;
using System.Reflection;
using Aspire.Hosting.Sdk;
using NuGet.RuntimeModel;

namespace Aspire.RuntimeIdentifier.Tool;

sealed class Program
{
static int Main(string[] args)
{
CliRootCommand rootCommand = new("Aspire.RuntimeIdentifier.Tool v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion)
{
TreatUnmatchedTokensAsErrors = true
};

CliOption<string?> runtimeGraphPathOption = new("--runtimeGraphPath", "-rgp")
joperezr marked this conversation as resolved.
Show resolved Hide resolved
{
Description = "Path to runtime graph path to use for RID mapping.",
Required = true
};

CliOption<string?> netcoreSdkRuntimeIdentifierOption = new("--netcoreSdkRuntimeIdentifier", "-r")
{
Description = "RID to use for finding the best applicable RID from mapping.",
Required = true
};

CliOption<string[]> supportedRidsOption = new("--supportedRids", "-sr")
{
Description = "List of RIDs that are supported. Comma-separated.",
Required = true,
AllowMultipleArgumentsPerToken = true,
joperezr marked this conversation as resolved.
Show resolved Hide resolved
Arity = ArgumentArity.OneOrMore,
CustomParser = ParseSupportedRidsArgument
};

rootCommand.Options.Add(runtimeGraphPathOption);
rootCommand.Options.Add(netcoreSdkRuntimeIdentifierOption);
rootCommand.Options.Add(supportedRidsOption);
rootCommand.SetAction((ParseResult parseResult) =>
{
string rgp = parseResult.GetValue(runtimeGraphPathOption) ?? throw new InvalidOperationException("The --runtimeGraphPath argument is required.");

if (!File.Exists(rgp))
{
throw new FileNotFoundException("File {0} does not exist. Please ensure the runtime graph path exists.", rgp);
}

RuntimeGraph graph = JsonRuntimeFormat.ReadRuntimeGraph(rgp);

var ridToUse = parseResult.GetValue(netcoreSdkRuntimeIdentifierOption);

var supportedRids = parseResult.GetValue(supportedRidsOption);

string? bestRidForPlatform = NuGetUtils.GetBestMatchingRid(graph, ridToUse!, supportedRids!, out bool wasInGraph);

if (!wasInGraph)
{
#pragma warning disable CA2201 // Do not raise reserved exception types
throw new ApplicationException("Unable to find the best rid to use");
#pragma warning restore CA2201 // Do not raise reserved exception types
joperezr marked this conversation as resolved.
Show resolved Hide resolved
}

Console.WriteLine(bestRidForPlatform);
return 0;
});

return rootCommand.Parse(args).Invoke();
}

private static string[]? ParseSupportedRidsArgument(ArgumentResult result)
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised we need to write custom code for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

{
List<string> args = new();

foreach (var token in result.Tokens)
{
args.AddRange(token.Value.Split(','));
}

return args.ToArray();
}
}
53 changes: 51 additions & 2 deletions src/Aspire.Hosting.Sdk/SDK/Sdk.in.targets
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<Warning Code="ASPIRE003" Text="$(MSBuildProjectName) is a .NET Aspire AppHost project that requires Visual Studio version 17.10 or above to work correctly. You are using version $(MSBuildVersion)." />
</Target>

<PropertyGroup>
<AspireRidToolRoot>$(MSBuildThisFileDirectory)..\tools\@DefaultTargetFramework@\</AspireRidToolRoot>
<AspireRidToolDirectory>$([MSBuild]::NormalizePath('$(AspireRidToolRoot)\'))</AspireRidToolDirectory>
<AspireRidToolExecutable>$(AspireRidToolDirectory)Aspire.RuntimeIdentifier.Tool.dll</AspireRidToolExecutable>
</PropertyGroup>

<!-- This target extracts the version of Aspire.Hosting.AppHost referenced by the project, and adds
a reference to Aspire.Dashboard.Sdk and Aspire.Hosting.Orchestration for the build-time platform using
the same version. This is done here dynamically to avoid having to pull in DCP and Dashboard packages
Expand Down Expand Up @@ -83,10 +89,53 @@
<Error Condition="'$(_AppHostVersion)' == ''"
Text="$(MSBuildProjectName) is a .NET Aspire AppHost project that needs a package reference to Aspire.Hosting.AppHost version 8.2.0 or above to work correctly." />

<!--The following is the list of the RIDs that we currently multitarget for DCP and Dashboard packages-->
<ItemGroup>
<_DashboardAndDCPSupportedTargetingRIDs Include="win-x64" />
<_DashboardAndDCPSupportedTargetingRIDs Include="win-x86" />
<_DashboardAndDCPSupportedTargetingRIDs Include="win-arm64" />
<_DashboardAndDCPSupportedTargetingRIDs Include="linux-x64" />
<_DashboardAndDCPSupportedTargetingRIDs Include="linux-arm64" />
<_DashboardAndDCPSupportedTargetingRIDs Include="osx-x64" />
<_DashboardAndDCPSupportedTargetingRIDs Include="osx-arm64" />
</ItemGroup>

<!-- If running in .NET Core, DOTNET_HOST_PATH is set to point to the dotnet executable being used
for the build. -->
<PropertyGroup>
<_DotNetHostPath>$(DOTNET_HOST_PATH)</_DotNetHostPath>
</PropertyGroup>

<!-- If running on .NET Framework MSBuild, then DOTNET_HOST_PATH won't be set, so we need to construct
the path using well-known properties. -->
<PropertyGroup Condition="'$(_DotNetHostPath)' == ''">
<_DotNetHostDirectory>$(NetCoreRoot)</_DotNetHostDirectory>
<_DotNetHostFileName>dotnet</_DotNetHostFileName>
<_DotNetHostFileName Condition="'$(OS)' == 'Windows_NT'">dotnet.exe</_DotNetHostFileName>

<_DotNetHostPath>$(_DotNetHostDirectory)\$(_DotNetHostFileName)</_DotNetHostPath>
</PropertyGroup>

<!-- Call Aspire.RuntimeIdentifier.Tool to get the RIDs for Dashboard and DCP packages -->
<Exec Command="&quot;$(_DotNetHostPath)&quot; exec &quot;$(AspireRidToolExecutable)&quot; -rgp &quot;$(BundledRuntimeIdentifierGraphFile)&quot; -sr &quot;@(_DashboardAndDCPSupportedTargetingRIDs -> '%(Identity)', ',')&quot; -r &quot;$(NETCoreSdkRuntimeIdentifier)&quot;"
ConsoleToMSBuild="true"
StandardOutputImportance="Low"
IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="_AspireRidToolExitCode" />
<Output TaskParameter="ConsoleOutput" ItemName="_AspireRidToolOutput" />
</Exec>

<Error Condition="$(_AspireRidToolExitCode) != 0" Text="Failed to run Aspire.RuntimeIdentifier.Tool. Exit code: $(_AspireRidToolExitCode). Output: @(_AspireRidToolOutput)" />

<PropertyGroup>
<_DashboardAndDcpRID>@(_AspireRidToolOutput)</_DashboardAndDcpRID>
</PropertyGroup>


<!-- Now that we have the version, we add the package references -->
<ItemGroup>
<PackageReference Include="Aspire.Dashboard.Sdk.$(NETCoreSdkRuntimeIdentifier)" Version="$(_AppHostVersion)" IsImplicitlyDefined="true" />
<PackageReference Include="Aspire.Hosting.Orchestration.$(NETCoreSdkRuntimeIdentifier)" Version="$(_AppHostVersion)" IsImplicitlyDefined="true" />
<PackageReference Include="Aspire.Dashboard.Sdk.$(_DashboardAndDcpRID)" Version="$(_AppHostVersion)" IsImplicitlyDefined="true" />
<PackageReference Include="Aspire.Hosting.Orchestration.$(_DashboardAndDcpRID)" Version="$(_AppHostVersion)" IsImplicitlyDefined="true" />
</ItemGroup>
</Target>

Expand Down
16 changes: 16 additions & 0 deletions tests/Aspire.Hosting.Sdk.Tests/Aspire.Hosting.Sdk.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\src\Aspire.Hosting.Sdk\Aspire.RuntimeIdentifier.Tool\NuGetUtils.cs" Link="Product\NuGetUtils.cs" />
<None Include="$(BundledRuntimeIdentifierGraphFile)" Link="RuntimeIdentifierGraph.json" CopyToOutputDirectory="Always" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NuGet.ProjectModel" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions tests/Aspire.Hosting.Sdk.Tests/NuGetUtils.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using NuGet.RuntimeModel;
using Xunit;

namespace Aspire.Hosting.Sdk.Tests;

public class NuGetUtilsTests
{
[Theory]
// Matching RID cases
[InlineData("win-x64", "win-x64")]
[InlineData("win-x86", "win-x86")]
[InlineData("win-arm64", "win-arm64")]
[InlineData("linux-x64", "linux-x64")]
[InlineData("linux-arm64", "linux-arm64")]
[InlineData("osx-x64", "osx-x64")]
[InlineData("osx-arm64", "osx-arm64")]

//Compatible RID cases
[InlineData("rhel.8-x64", "linux-x64")] // https://github.com/dotnet/aspire/issues/5486
[InlineData("ubuntu.23.04-x64", "linux-x64")]
[InlineData("fedora.39-x64", "linux-x64")]
[InlineData("linux-musl-x64", "linux-x64")]
public void RightRIDIsSelected(string inputRID, string expectedRID)
{
RuntimeGraph graph = JsonRuntimeFormat.ReadRuntimeGraph("RuntimeIdentifierGraph.json");

var result = NuGetUtils.GetBestMatchingRid(graph, inputRID, new[] { "win-x64", "win-arm64", "win-x86",
"linux-x64", "linux-arm64",
"osx-x64", "osx-arm64"}, out bool wasInGraph);

Assert.Equal(expectedRID, result);
Assert.True(wasInGraph);
}
}
Loading