Skip to content

Commit efbcaca

Browse files
committed
Make all innner build RIDs visible to restore
Fix #871
1 parent d25fe87 commit efbcaca

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ Copyright (c) .NET Foundation. All rights reserved.
352352

353353
</Target>
354354

355+
<!--
356+
============================================================
357+
GetAllRuntimeIdentifiers
358+
============================================================
359+
-->
360+
<Target Name="GetAllRuntimeIdentifiers"
361+
Returns="$(RuntimeIdentifiers);$(RuntimeIdentifier)" />
362+
355363
<!--
356364
============================================================
357365
Project Capabilities

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,48 @@ Copyright (c) .NET Foundation. All rights reserved.
3030
<Target Name="Publish">
3131
<Error Text="The 'Publish' target is not supported without specifying a target framework. The current project targets multiple frameworks, please specify the framework for the published application." />
3232
</Target>
33+
34+
<!--
35+
============================================================
36+
GetAllRuntimeIdentifiers
37+
38+
Outer build implementation of GetAllRuntimeIdentifiers returns
39+
a union of all runtime identifiers used across inner and outer
40+
build evaluations.
41+
42+
It is further set to run before '_GenerateRestoreProjecSpec'
43+
(note that running only 'Restore' is too late and will not work
44+
with solution level restore). This ensures that any conditioning
45+
of runtime identifiers against TargetFramework does not prevent
46+
restore from providing the necessary RID-specific assets for all
47+
inner builds.
3348
49+
It also brings parity to VS vs. command line behavior in this
50+
scenario because VS passes all of the information from each
51+
configured inner build to restore, whereas command-line restore
52+
without this target would only use the runtime identifiers that
53+
are statically set in the outer evaluation.
54+
============================================================
55+
-->
56+
<Target Name="GetAllRuntimeIdentifiers"
57+
Returns="$(RuntimeIdentifiers)"
58+
BeforeTargets="_GenerateRestoreProjectSpec">
59+
60+
<ItemGroup>
61+
<_GetAllRuntimeIdentifiersTargetFrameworks Include="$(TargetFrameworks)" />
62+
<_AllRuntimeIdentifiers Include="$(RuntimeIdentifiers);$(RuntimeIdentifier)" />
63+
</ItemGroup>
64+
65+
<MSBuild Projects="$(MSBuildProjectFile)"
66+
Condition="'$(TargetFrameworks)' != ''"
67+
Targets="GetAllRuntimeIdentifiers"
68+
Properties="TargetFramework=%(_GetAllRuntimeIdentifiersTargetFrameworks.Identity)">
69+
<Output ItemName="_AllRuntimeIdentifiers" TaskParameter="TargetOutputs" />
70+
</MSBuild>
71+
72+
<PropertyGroup>
73+
<RuntimeIdentifiers>@(_AllRuntimeIdentifiers->Distinct())</RuntimeIdentifiers>
74+
</PropertyGroup>
75+
</Target>
76+
3477
</Project>

test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,33 @@ public void It_appends_rid_to_outdir_correctly(string identifier, string rid, bo
173173
}
174174
}
175175

176+
[Fact]
177+
public void It_builds_multitargeted_with_default_rid()
178+
{
179+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
180+
{
181+
return;
182+
}
183+
184+
var testAsset = _testAssetsManager
185+
.CopyTestAsset("HelloWorld")
186+
.WithSource()
187+
.WithProjectChanges(project =>
188+
{
189+
var ns = project.Root.Name.Namespace;
190+
var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First();
191+
propertyGroup.Element(ns + "TargetFramework").Remove();
192+
propertyGroup.Add(new XElement(ns + "TargetFrameworks", "net46;netcoreapp1.1"));
193+
})
194+
.Restore();
195+
196+
var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot);
197+
buildCommand
198+
.Execute()
199+
.Should()
200+
.Pass();
201+
}
202+
176203
[Theory]
177204
[InlineData("win7-x86", "x86")]
178205
[InlineData("win8-x86-aot", "x86")]

0 commit comments

Comments
 (0)