Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 3af6975

Browse files
committed
Add support for single and cross targeting NETStandard P2P references
1 parent 67fbbe3 commit 3af6975

16 files changed

Lines changed: 186 additions & 17 deletions

build.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<NuGetRestore Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_library_with_non_nugetized_reference\b.sln" />
8181
<NuGetRestore Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_multi_platform_solution\forms.sln" />
8282
<NuGetRestore Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_library_with_json_dependencies\project.json" />
83+
<MSBuildRestore Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_packaging_project_with_netstandard\a.nuproj" />
8384

8485
<MSBuildRestore Include="src\Build\NuGet.Build.Packaging.sln" />
8586
<MSBuildRestore Include="src\VisualStudio\NuGet.Packaging.VisualStudio.sln" />

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Authoring.props

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ Copyright (c) .NET Foundation. All rights reserved.
1111
-->
1212
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1313
<PropertyGroup>
14-
<TargetFrameworkMoniker>NuGet,Version=v1.0</TargetFrameworkMoniker>
14+
<!--<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
15+
<TargetFramework>netstandard1.0</TargetFramework>
16+
<TargetFrameworkMoniker>.NETStandard,Version=1.0</TargetFrameworkMoniker>
17+
<NuGetTargetMoniker>$(TargetFrameworkMoniker)</NuGetTargetMoniker>
18+
<PackageTargetFallback>net11;net20;net35;net40;net403;net45;net451;net452;net46;net461;net462;netcore;netcore45;netcore451;netcore50;win8;win81;win10;sl4;sl5;wp;wp7;wp75;wp8;wp81;wpa81;uap;uap10;netstandard1.0;netstandard1.1;netstandard1.2;netstandard1.3;netstandard1.4;netstandard1.5;netstandard1.6;netstandard2.0;netcoreapp1.0;netcoreapp2.0;monoandroid;monotouch;monomac;xamarinios;xamarinmac;xamarinpsthree;xamarinpsfour;xamarinpsvita;xamarinwatchos;xamarintvos;xamarinxboxthreesixty;xamarinxboxone</PackageTargetFallback>-->
19+
1520
<TargetExt>.nupkg</TargetExt>
1621

1722
<!-- The Pack target generates to the output path directly -->

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Authoring.targets

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ Copyright (c) .NET Foundation. All rights reserved.
1919
<ResolveAssemblyReferencesDependsOn />
2020
</PropertyGroup>
2121

22+
<ItemDefinitionGroup>
23+
<!-- This turns off _GetProjectReferenceTargetFrameworkProperties which passes down
24+
our TF to referenced projects and causes build to fail even if we don't really
25+
need to match up with referenced projects outputs. We're basically using the
26+
documented escape hatch, see
27+
https://github.com/Microsoft/msbuild/blob/2634f05a660b14c64ae4e924d900dd200d5032e7/src/Tasks/Microsoft.Common.CurrentVersion.targets#L1537
28+
-->
29+
<_MSBuildProjectReferenceExistent>
30+
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
31+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
32+
<AdditionalProperties>FromPackagingProject=true</AdditionalProperties>
33+
</_MSBuildProjectReferenceExistent>
34+
</ItemDefinitionGroup>
35+
2236
<!-- Just to make it easy for consumers to request the TargetPath as usual but get the
2337
actual package file, which contains the PackageVersion and will be dynamic therefore. -->
2438
<Target Name="UpdateTargetPath"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!--
2+
***********************************************************************************************
3+
Microsoft.NuGet.Build.Packaging.CrossTargeting.targets
4+
5+
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
6+
created a backup copy. Incorrect changes to this file will make it
7+
impossible to load or build your projects from the command-line or the IDE.
8+
9+
Copyright (c) .NET Foundation. All rights reserved.
10+
***********************************************************************************************
11+
-->
12+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
13+
14+
<Target Name="GetNativeManifest" />
15+
<Target Name="GetCopyToOutputDirectoryItems" />
16+
17+
<!--
18+
============================================================
19+
GetTargetPathWithTargetPlatformMoniker
20+
NOTE: depends on Microsoft.Common.CrossTargeting.targets
21+
22+
When cross-targeting and the authoring project references a
23+
nugetized library, return all the determined target paths.
24+
============================================================
25+
-->
26+
<Target Name="GetTargetPathWithTargetPlatformMoniker"
27+
DependsOnTargets="_SetGetTargetPathWithTargetPlatformMonikerInnerTarget;DispatchToInnerBuilds"
28+
Returns="@(InnerOutput)">
29+
<ItemGroup>
30+
<InnerOutput>
31+
<IsNuGetized>true</IsNuGetized>
32+
</InnerOutput>
33+
</ItemGroup>
34+
</Target>
35+
36+
<Target Name="_SetGetTargetPathWithTargetPlatformMonikerInnerTarget">
37+
<PropertyGroup>
38+
<InnerTargets>GetTargetPathWithTargetPlatformMoniker</InnerTargets>
39+
</PropertyGroup>
40+
</Target>
41+
42+
<!--
43+
============================================================
44+
GetPackageContents
45+
Cross-targeting version of GetPackageContents.
46+
NOTE: depends on Microsoft.Common.CrossTargeting.targets
47+
48+
[OUT]
49+
@(InnerOutput) - The combined output items of the inner targets across
50+
all builds.
51+
============================================================
52+
-->
53+
<Target Name="GetPackageContents" DependsOnTargets="_SetGetPackageContentsInnerTarget;DispatchToInnerBuilds" Returns="@(InnerOutput)" />
54+
55+
<Target Name="_SetGetPackageContentsInnerTarget">
56+
<PropertyGroup>
57+
<InnerTargets>GetPackageContents</InnerTargets>
58+
</PropertyGroup>
59+
</Target>
60+
61+
</Project>

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Tasks.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
<Content Include="FodyWeavers.xml" />
1818
<Content Include="NuGet.Build.Packaging.props">
1919
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
20-
<SubType>Designer</SubType>
2120
</Content>
2221
<Content Include="NuGet.Build.Packaging.targets">
2322
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24-
<SubType>Designer</SubType>
23+
</Content>
24+
<Content Include="NuGet.Build.Packaging.CrossTargeting.targets">
25+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2526
</Content>
2627
<Content Include="MSBuild\Imports\Microsoft.Common.Props\ImportBefore\Microsoft.NuGet.Packaging.ImportBefore.props">
2728
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -31,9 +32,9 @@
3132
</Content>
3233
<Content Include="NuGet.Build.Packaging.Authoring.targets">
3334
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
35+
<SubType>Designer</SubType>
3436
</Content>
3537
<None Include="NuGet.Build.Packaging.Version.props">
36-
<SubType>Designer</SubType>
3738
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3839
</None>
3940
<None Include="NuGet.Build.Packaging.Tasks.targets">

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Copyright (c) .NET Foundation. All rights reserved.
1717
<!-- Disable built-in Pack -->
1818
<NuGetBuildTasksPackTargets>NO-SDK-PACK</NuGetBuildTasksPackTargets>
1919
<ImportNuGetBuildTasksPackTargetsFromSdk>false</ImportNuGetBuildTasksPackTargetsFromSdk>
20+
<!-- Ensure the right value is always available -->
21+
<IsCrossTargetingBuild Condition="'$(IsCrossTargetingBuild)' == '' and '$(TargetFrameworks)' != '' and '$(TargetFramework)' == ''">true</IsCrossTargetingBuild>
2022
</PropertyGroup>
2123

2224
<PropertyGroup>

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Copyright (c) .NET Foundation. All rights reserved.
6262
<ItemDefinitionGroup>
6363
<TargetPathWithTargetPlatformMoniker>
6464
<IsPackable>$(IsPackable)</IsPackable>
65-
<IsNuGetized>$(IsNuGetized)</IsNuGetized>
65+
<IsNuGetized>true</IsNuGetized>
6666
</TargetPathWithTargetPlatformMoniker>
6767
</ItemDefinitionGroup>
6868

@@ -581,4 +581,5 @@ Copyright (c) .NET Foundation. All rights reserved.
581581
</Target>
582582

583583
<Import Project="NuGet.Build.Packaging.Authoring.targets" Condition="'$(IsPackagingProject)' == 'true'" />
584+
<Import Project="NuGet.Build.Packaging.CrossTargeting.targets" Condition="'$(IsCrossTargetingBuild)' == 'true' And '$(FromPackagingProject)' == 'true'" />
584585
</Project>

src/Build/NuGet.Build.Packaging.Tests/Builder.NuGetizer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ public TargetResult(BuildResult result, string target, TestOutputLogger logger)
8484

8585
public void AssertSuccess(ITestOutputHelper output)
8686
{
87+
if (!BuildResult.ResultsByTarget.ContainsKey(Target))
88+
{
89+
output.WriteLine(this.ToString());
90+
Assert.False(true, "Build results do not contain output for target " + Target);
91+
}
92+
8793
if (ResultCode != TargetResultCode.Success)
8894
output.WriteLine(this.ToString());
8995

src/Build/NuGet.Build.Packaging.Tests/Builder.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
/// </summary>
1515
public static partial class Builder
1616
{
17+
#if DEV15
18+
const string ToolsVersion = "15.0";
19+
#else
20+
const string ToolsVersion = "14.0";
21+
#endif
22+
1723
public static BuildResult Build(string projectOrSolution, string targets, Dictionary<string, string> properties = null, ILogger logger = null)
1824
{
1925
if (!Path.IsPathRooted(projectOrSolution))
@@ -33,7 +39,7 @@ public static BuildResult Build(string projectOrSolution, string targets, Dictio
3339
if (Path.GetExtension(projectOrSolution) != ".sln")
3440
AddSolutionConfiguration(projectOrSolution, properties);
3541

36-
var request = new BuildRequestData(projectOrSolution, properties, "14.0", targets.Split(','), null);
42+
var request = new BuildRequestData(projectOrSolution, properties, ToolsVersion, targets.Split(','), null);
3743
var parameters = new BuildParameters
3844
{
3945
GlobalProperties = properties,

src/Build/NuGet.Build.Packaging.Tests/Scenarios/given_a_packaging_project/a.nuproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Scenario.props))\Scenario.props" />
44
<PropertyGroup>
5-
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
5+
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
6+
<TargetFramework>netstandard1.0</TargetFramework>
7+
<PackageTargetFallback>net11;net20;net35;net40;net403;net45;net451;net452;net46;net461;net462;netcore;netcore45;netcore451;netcore50;win8;win81;win10;sl4;sl5;wp;wp7;wp75;wp8;wp81;wpa81;uap;uap10;netstandard1.0;netstandard1.1;netstandard1.2;netstandard1.3;netstandard1.4;netstandard1.5;netstandard1.6;netstandard2.0;netcoreapp1.0;netcoreapp2.0;monoandroid;monotouch;monomac;xamarinios;xamarinmac;xamarinpsthree;xamarinpsfour;xamarinpsvita;xamarinwatchos;xamarintvos;xamarinxboxthreesixty;xamarinxboxone</PackageTargetFallback>
68
<PackageId>a.package</PackageId>
79
<PackageVersion>1.0.0</PackageVersion>
810
</PropertyGroup>

0 commit comments

Comments
 (0)