-
Notifications
You must be signed in to change notification settings - Fork 609
Use an MSBuild Task for RID selection instead of shelling out #8686
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.Build.Framework; | ||
using Aspire.Hosting.Sdk; | ||
using NuGet.RuntimeModel; | ||
|
||
namespace Aspire.RuntimeIdentifier.Tool; | ||
|
||
/// <summary> | ||
/// This task uses the given RID graph in a given SDK to pick the best match from among a set of supported RIDs for the current RID | ||
/// </summary> | ||
public sealed class PickBestRid : Microsoft.Build.Utilities.Task | ||
{ | ||
/// <summary> | ||
/// The path to the RID graph to read | ||
/// </summary> | ||
[Required] | ||
public string RuntimeGraphPath { get; set; } | ||
|
||
/// <summary> | ||
/// The RID of the current process | ||
/// </summary> | ||
[Required] | ||
public string CurrentRid { get; set; } | ||
|
||
/// <summary> | ||
/// All of the RIDs that Aspire supports | ||
/// </summary> | ||
[Required] | ||
public string[]? SupportedRids { get; set; } | ||
|
||
/// <summary> | ||
/// The solution to the puzzle | ||
/// </summary> | ||
[Output] | ||
public string MatchingRid { get; set; } | ||
|
||
/// <summary> | ||
/// Computes the thing | ||
/// </summary> | ||
/// <returns></returns> | ||
public override bool Execute() | ||
{ | ||
if (!File.Exists(RuntimeGraphPath)) | ||
{ | ||
Log.LogError("File {0} does not exist. Please ensure the runtime graph path exists.", RuntimeGraphPath); | ||
return !Log.HasLoggedErrors; | ||
} | ||
|
||
RuntimeGraph graph = JsonRuntimeFormat.ReadRuntimeGraph(RuntimeGraphPath); | ||
string? bestRidForPlatform = NuGetUtils.GetBestMatchingRid(graph, CurrentRid, SupportedRids, out bool wasInGraph); | ||
|
||
if (!wasInGraph) | ||
{ | ||
Log.LogError("Unable to find a matching RID for {0} from among {1} in graph {2}", CurrentRid, string.Join(",", SupportedRids), RuntimeGraphPath); | ||
return !Log.HasLoggedErrors; | ||
} | ||
|
||
MatchingRid = bestRidForPlatform; | ||
return true; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
This defaulting needs to happen in the SDK targets so this metadata affects NuGet Restore. | ||
--> | ||
<ItemGroup Condition="'$(IsAspireHost)' == 'true'"> | ||
|
||
<ProjectReference Update="@(ProjectReference)"> | ||
<IsAspireProjectResource Condition="'%(IsAspireProjectResource)' != 'false'">true</IsAspireProjectResource> | ||
|
||
|
@@ -43,11 +43,7 @@ | |
<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> | ||
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)../tasks/netstandard2.0/Aspire.AppHost.Tasks.dll" TaskName="PickBestRid" /> | ||
|
||
<!-- 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 | ||
|
@@ -66,7 +62,7 @@ | |
<_AppHostVersion>%(_AppHostPackageReference.Version)</_AppHostVersion> | ||
</PropertyGroup> | ||
|
||
<!-- If the version is still empty, then we assume the project is using Central Package Management, | ||
<!-- If the version is still empty, then we assume the project is using Central Package Management, | ||
and we try to extract the PackageVersion Items. --> | ||
<ItemGroup Condition="'$(_AppHostVersion)' == ''"> | ||
<_AppHostPackageReference /> | ||
|
@@ -91,52 +87,19 @@ | |
</PropertyGroup> | ||
|
||
<!-- At this point, we should have the version either by CPM or PackageReference, so we fail if not. --> | ||
<Error Condition="'$(_AppHostVersion)' == ''" | ||
<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" /> | ||
<_DashboardAndDCPSupportedTargetingRIDs Include="win-x64;win-x86;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
</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> | ||
Comment on lines
-108
to
-122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. none of this is necessary if we're not spawning binaries anymore in the SDK-delivered targets |
||
|
||
<!-- Call Aspire.RuntimeIdentifier.Tool to get the RIDs for Dashboard and DCP packages --> | ||
<Exec Command=""$(_DotNetHostPath)" exec "$(AspireRidToolExecutable)" --runtimeGraphPath "$(BundledRuntimeIdentifierGraphFile)" --supportedRids "@(_DashboardAndDCPSupportedTargetingRIDs -> '%(Identity)', ',')" --netcoreSdkRuntimeIdentifier "$(NETCoreSdkRuntimeIdentifier)"" | ||
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> | ||
<!-- Compute the RID for Dashboard and DCP packages --> | ||
<PickBestRid RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)" CurrentRid="$(NETCoreSdkRuntimeIdentifier)" SupportedRids="@(_DashboardAndDCPSupportedTargetingRIDs)"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe? I was mostly focused on translating the behaviors that existed before. I like than an explicit lookup will have a clearer error message than a missing implicitly-defined PackageReference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most use cases are expressed with portable rids. Either the portable rid comes from the user, or it's the one from the SDK. For the latter, rather than mapping NETCoreSdkRuntimeIdentifier via the rid graph, NETCoreSdkPortableRuntimeIdentifier can be used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a linux-musl-x64 system, should this use linux-x64 assets? Or would those be binary incompatible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<Output TaskParameter="MatchingRid" PropertyName="_DashboardAndDcpRID" /> | ||
</PickBestRid> | ||
|
||
|
||
<!-- Now that we have the version, we add the package references --> | ||
<ItemGroup> | ||
<PackageReference Include="Aspire.Dashboard.Sdk.$(_DashboardAndDcpRID)" Version="$(_AppHostVersion)" IsImplicitlyDefined="true" /> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose ns2.0 so that we should work in VS and in CLI. I've tested both and that does seem to be the case.