Skip to content

Commit 1df8f4f

Browse files
committed
Enable "portable" RID graph
1 parent 16466e0 commit 1df8f4f

11 files changed

+624
-14
lines changed

src/Layout/redist/PortableRuntimeIdentifierGraph.json

Lines changed: 464 additions & 0 deletions
Large diffs are not rendered by default.

src/Layout/redist/targets/BuildToolsetTasks.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
<UsingTask TaskName="ZipFileCreateFromDirectory" AssemblyFile="$(ToolsetTaskDll)"/>
2828
<UsingTask TaskName="OverrideAndCreateBundledNETCoreAppPackageVersion" AssemblyFile="$(ToolsetTaskDll)"/>
2929
<UsingTask TaskName="OverrideWasmRuntimePackVersions" AssemblyFile="$(ToolsetTaskDll)"/>
30+
<UsingTask TaskName="UpdatePortableRuntimeIdentifierGraph" AssemblyFile="$(ToolsetTaskDll)"/>
3031

3132
</Project>

src/Layout/redist/targets/GenerateLayout.targets

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
<Project>
2+
3+
<Target Name="PublishPortableRuntimeIdentifierGraph"
4+
BeforeTargets="Build">
5+
6+
<UpdatePortableRuntimeIdentifierGraph
7+
InputFile="PortableRuntimeIdentifierGraph.json"
8+
OutputFile="$(OutputPath)/PortableRuntimeIdentifierGraph.json"
9+
AdditionalRuntimeIdentifiers="@(AdditionalRuntimeIdentifier)"
10+
/>
11+
12+
</Target>
13+
214
<Target Name="PublishVersionFile"
315
BeforeTargets="Build">
416

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Security.Cryptography;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using Microsoft.Build.Framework;
12+
using Microsoft.Build.Utilities;
13+
using Newtonsoft.Json;
14+
using Newtonsoft.Json.Linq;
15+
16+
namespace Microsoft.DotNet.Cli.Build
17+
{
18+
public class UpdatePortableRuntimeIdentifierGraph : Task
19+
{
20+
[Required]
21+
public string InputFile { get; set; }
22+
23+
[Required]
24+
public string OutputFile { get; set; }
25+
26+
27+
// ItemSpec should be a RID, and "Imports" metadata should be a semicolon-separated list of RIDs that the ItemSpec RID imports
28+
public ITaskItem[] AdditionalRuntimeIdentifiers { get; set; }
29+
30+
public override bool Execute()
31+
{
32+
JToken json;
33+
34+
using (var file = File.OpenText(InputFile))
35+
using (JsonTextReader reader = new JsonTextReader(file))
36+
{
37+
json = JObject.ReadFrom(reader);
38+
}
39+
40+
JObject runtimes = (JObject) json["runtimes"];
41+
42+
if (AdditionalRuntimeIdentifiers != null)
43+
{
44+
foreach (var rid in AdditionalRuntimeIdentifiers)
45+
{
46+
var importedRids = rid.GetMetadata("Imports").Split(';');
47+
runtimes.Add(rid.ItemSpec, new JObject(new JProperty("#import", new JArray(importedRids))));
48+
}
49+
}
50+
51+
using (var file = File.CreateText(OutputFile))
52+
using (var writer = new JsonTextWriter(file) { Formatting = Formatting.Indented })
53+
{
54+
json.WriteTo(writer);
55+
}
56+
57+
return true;
58+
}
59+
}
60+
}

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ Copyright (c) .NET Foundation. All rights reserved.
444444
<ResolveReadyToRunCompilers RuntimePacks="@(ResolvedRuntimePack)"
445445
Crossgen2Packs="@(ResolvedCrossgen2Pack)"
446446
TargetingPacks="@(ResolvedTargetingPack)"
447-
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
447+
RuntimeGraphPath="$(RuntimeIdentifierGraphPath)"
448448
NETCoreSdkRuntimeIdentifier="$(NETCoreSdkRuntimeIdentifier)"
449449
EmitSymbols="$(PublishReadyToRunEmitSymbols)"
450450
ReadyToRunUseCrossgen2="$(PublishReadyToRunUseCrossgen2)"

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.DesignerSupport.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Copyright (c) .NET Foundation. All rights reserved.
6868
ResolvedNuGetFiles="@(NativeCopyLocalItems);@(ResourceCopyLocalItems);@(RuntimeCopyLocalItems)"
6969
ResolvedRuntimeTargetsFiles="@(RuntimeTargetsCopyLocalItems)"
7070
TargetFramework="$(TargetFramework)"
71-
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
71+
RuntimeGraphPath="$(RuntimeIdentifierGraphPath)"
7272
IncludeProjectsNotInAssetsFile="$(IncludeProjectsNotInAssetsFileInDepsFile)"
7373
/>
7474

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ Copyright (c) .NET Foundation. All rights reserved.
329329
<ResolveReadyToRunCompilers RuntimePacks="@(ResolvedRuntimePack)"
330330
Crossgen2Packs="@(ResolvedCrossgen2Pack)"
331331
TargetingPacks="@(ResolvedTargetingPack)"
332-
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
332+
RuntimeGraphPath="$(RuntimeIdentifierGraphPath)"
333333
NETCoreSdkRuntimeIdentifier="$(NETCoreSdkRuntimeIdentifier)"
334334
EmitSymbols="$(PublishReadyToRunEmitSymbols)"
335335
ReadyToRunUseCrossgen2="$(PublishReadyToRunUseCrossgen2)"
@@ -1013,7 +1013,7 @@ Copyright (c) .NET Foundation. All rights reserved.
10131013
<_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(MicrosoftNETPlatformLibrary)" />
10141014
<_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(SelfContained)" />
10151015
<_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(IncludeFileVersionsInDependencyFile)" />
1016-
<_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(BundledRuntimeIdentifierGraphFile)" />
1016+
<_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(RuntimeIdentifierGraphPath)" />
10171017
<_GeneratePublishDependencyFilePropertyInputsCacheToHash Include="$(IncludeProjectsNotInAssetsFileInDepsFile)" />
10181018
</ItemGroup>
10191019

@@ -1099,7 +1099,7 @@ Copyright (c) .NET Foundation. All rights reserved.
10991099
IsSelfContained="$(SelfContained)"
11001100
IsSingleFile="$(_IsSingleFilePublish)"
11011101
IncludeRuntimeFileVersions="$(IncludeFileVersionsInDependencyFile)"
1102-
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
1102+
RuntimeGraphPath="$(RuntimeIdentifierGraphPath)"
11031103
IncludeProjectsNotInAssetsFile="$(IncludeProjectsNotInAssetsFileInDepsFile)"/>
11041104

11051105
<ItemGroup>

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.props

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ Copyright (c) .NET Foundation. All rights reserved.
1717

1818
<Import Project="$(NETCoreSdkBundledVersionsProps)" Condition="Exists('$(NETCoreSdkBundledVersionsProps)')" />
1919

20-
<PropertyGroup>
21-
<!-- Set RuntimeIdentifier graph for NuGet (this needs to be after NETCoreSdkBundledVersionsProps is imported, as that's where
22-
BundledRuntimeIdentifierGraphFile is set. -->
23-
<RuntimeIdentifierGraphPath Condition="'$(RuntimeIdentifierGraphPath)' == ''">$(BundledRuntimeIdentifierGraphFile)</RuntimeIdentifierGraphPath>
24-
</PropertyGroup>
25-
2620
<PropertyGroup>
2721
<!-- Disable web SDK implicit package versions for ASP.NET packages, since the .NET SDK now handles that -->
2822
<EnableWebSdkImplicitPackageVersions>false</EnableWebSdkImplicitPackageVersions>

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Copyright (c) .NET Foundation. All rights reserved.
9595
TargetPlatformIdentifier="$(TargetPlatformIdentifier)"
9696
TargetPlatformVersion="$(TargetPlatformVersion)"
9797
TargetingPackRoot="$(NetCoreTargetingPackRoot)"
98-
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
98+
RuntimeGraphPath="$(RuntimeIdentifierGraphPath)"
9999
SelfContained="$(SelfContained)"
100100
ReadyToRunEnabled="$(PublishReadyToRun)"
101101
ReadyToRunUseCrossgen2="$(PublishReadyToRunUseCrossgen2)"
@@ -155,7 +155,7 @@ Copyright (c) .NET Foundation. All rights reserved.
155155
DotNetSingleFileHostExecutableNameWithoutExtension="$(_DotNetSingleFileHostExecutableNameWithoutExtension)"
156156
DotNetComHostLibraryNameWithoutExtension="$(_DotNetComHostLibraryNameWithoutExtension)"
157157
DotNetIjwHostLibraryNameWithoutExtension="$(_DotNetIjwHostLibraryNameWithoutExtension)"
158-
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
158+
RuntimeGraphPath="$(RuntimeIdentifierGraphPath)"
159159
KnownAppHostPacks="@(KnownAppHostPack)"
160160
NuGetRestoreSupported="$(_NuGetRestoreSupported)"
161161
EnableAppHostPackDownload="$(EnableAppHostPackDownload)"

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ Copyright (c) .NET Foundation. All rights reserved.
4848
<_GenerateSingleFileBundlePropertyInputsCache>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(_GenerateSingleFileBundlePropertyInputsCache)))</_GenerateSingleFileBundlePropertyInputsCache>
4949
</PropertyGroup>
5050

51+
<!-- For .NET 8 and higher, we will by default use a simplified "portable" RID graph -->
52+
<PropertyGroup Condition="'$(UseRidGraph)' == ''">
53+
<UseRidGraph Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '8.0'))">false</UseRidGraph>
54+
<UseRidGraph Condition="'$(UseRidGraph)' == ''">true</UseRidGraph>
55+
</PropertyGroup>
56+
57+
<PropertyGroup Condition="'$(RuntimeIdentifierGraphPath)' == ''">
58+
<RuntimeIdentifierGraphPath Condition="'$(UseRidGraph)' == 'true'">$(BundledRuntimeIdentifierGraphFile)</RuntimeIdentifierGraphPath>
59+
60+
<!-- The portable RID graph should be in the same directory as the full RID graph -->
61+
<RuntimeIdentifierGraphPath Condition="'$(UseRidGraph)' != 'true'">$([System.IO.Path]::GetDirectoryName($(BundledRuntimeIdentifierGraphFile)))/PortableRuntimeIdentifierGraph.json</RuntimeIdentifierGraphPath>
62+
</PropertyGroup>
63+
5164
<ItemGroup>
5265
<GenerateRuntimeConfigurationFilesInputs Include="$(ProjectAssetsFile)" />
5366
<GenerateRuntimeConfigurationFilesInputs Include="$(ProjectAssetsCacheFile)" />
@@ -288,7 +301,7 @@ Copyright (c) .NET Foundation. All rights reserved.
288301
ResolvedRuntimeTargetsFiles="@(RuntimeTargetsCopyLocalItems)"
289302
IsSelfContained="$(SelfContained)"
290303
IncludeRuntimeFileVersions="$(IncludeFileVersionsInDependencyFile)"
291-
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
304+
RuntimeGraphPath="$(RuntimeIdentifierGraphPath)"
292305
IncludeProjectsNotInAssetsFile="$(IncludeProjectsNotInAssetsFileInDepsFile)"
293306
ValidRuntimeIdentifierPlatformsForAssets="@(_ValidRuntimeIdentifierPlatformsForAssets)"/>
294307
<ItemGroup>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using FluentAssertions;
11+
using Microsoft.NET.TestFramework;
12+
using Microsoft.NET.TestFramework.Assertions;
13+
using Microsoft.NET.TestFramework.Commands;
14+
using Microsoft.NET.TestFramework.ProjectConstruction;
15+
using Xunit;
16+
using Xunit.Abstractions;
17+
18+
namespace Microsoft.NET.Build.Tests
19+
{
20+
public class RuntimeIdentifierGraphTests : SdkTest
21+
{
22+
public RuntimeIdentifierGraphTests(ITestOutputHelper log) : base(log)
23+
{
24+
}
25+
26+
[Theory]
27+
[InlineData("net7.0", null, true)]
28+
[InlineData("net8.0", null, false)]
29+
[InlineData("net7.0", "false", false)]
30+
[InlineData("net8.0", "true", true)]
31+
public void ItUsesCorrectRuntimeIdentifierGraph(string targetFramework, string useRidGraphValue, bool shouldUseFullRidGraph)
32+
{
33+
var testProject = new TestProject()
34+
{
35+
TargetFrameworks = targetFramework,
36+
IsExe = true
37+
};
38+
39+
if (useRidGraphValue != null)
40+
{
41+
testProject.AdditionalProperties["UseRidGraph"] = useRidGraphValue;
42+
}
43+
44+
testProject.RecordProperties("RuntimeIdentifierGraphPath");
45+
46+
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework + "_" + (useRidGraphValue ?? "null"));
47+
48+
var buildCommand = new BuildCommand(testAsset);
49+
50+
buildCommand.Execute()
51+
.Should()
52+
.Pass();
53+
54+
var runtimeIdentifierGraphPath = testProject.GetPropertyValues(testAsset.TestRoot)["RuntimeIdentifierGraphPath"];
55+
56+
if (shouldUseFullRidGraph)
57+
{
58+
Path.GetFileName(runtimeIdentifierGraphPath).Should().Be("RuntimeIdentifierGraph.json");
59+
}
60+
else
61+
{
62+
Path.GetFileName(runtimeIdentifierGraphPath).Should().Be("PortableRuntimeIdentifierGraph.json");
63+
}
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)