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

Commit 9485b7d

Browse files
committed
Improve default behavior for including framework references
Fixes NuGet/Home#5110
1 parent 4713efe commit 9485b7d

3 files changed

Lines changed: 96 additions & 16 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ Copyright (c) .NET Foundation. All rights reserved.
3535
<!-- Whether to include @(DebugSymbolsProjectOutputGroupOutput) items in the package -->
3636
<IncludeSymbolsInPackage Condition="'$(IncludeSymbolsInPackage)' == '' and '$(IncludeOutputsInPackage)' == 'true' and '$(Configuration)' == 'Debug'">true</IncludeSymbolsInPackage>
3737
<!-- Whether to include framework references (%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}') in the package -->
38+
3839
<!-- Only default to true if the project isn't a nuget packaging project itself. -->
39-
<IncludeFrameworkReferencesInPackage Condition="'$(IncludeFrameworkReferencesInPackage)' == '' and '$(IsPackagingProject)' != 'true'">true</IncludeFrameworkReferencesInPackage>
40+
<_DefaultIncludeFrameworkReferencesInPackage Condition="'$(PrimaryOutputPackageFileKind)' == 'build' Or '$(PrimaryOutputPackageFileKind)' == 'tool' Or '$(PrimaryOutputPackageFileKind)' == 'tools'">false</_DefaultIncludeFrameworkReferencesInPackage>
41+
<_DefaultIncludeFrameworkReferencesInPackage Condition="'$(_DefaultIncludeFrameworkReferencesInPackage)' == ''">true</_DefaultIncludeFrameworkReferencesInPackage>
42+
<IncludeFrameworkReferencesInPackage Condition="'$(IncludeFrameworkReferencesInPackage)' == '' and '$(IsPackagingProject)' != 'true'">$(_DefaultIncludeFrameworkReferencesInPackage)</IncludeFrameworkReferencesInPackage>
4043

4144
<PackageRequireLicenseAcceptance Condition="'$(PackageRequireLicenseAcceptance)' == ''">false</PackageRequireLicenseAcceptance>
4245

src/Build/NuGet.Build.Packaging.Tests/NuGet.Build.Packaging.Tests.csproj

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
<Reference Include="System.Xml" />
1515
<Reference Include="System.Xml.Linq" />
1616
</ItemGroup>
17-
<ItemGroup>
18-
<PackageReference Include="GitInfo" Version="1.*" />
19-
<PackageReference Include="Microsoft.Build" Version="14.3.0" />
20-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="14.3.0" />
21-
<PackageReference Include="Newtonsoft.Json" Version="6.0.8" />
22-
<PackageReference Include="MSBuilder.Dump" Version="*" />
23-
<PackageReference Include="MSBuilder.DumpItems" Version="*" />
24-
<PackageReference Include="MSBuilder.Introspect" Version="*" />
25-
<PackageReference Include="xunit" Version="2.2.0" />
26-
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
27-
<PackageReference Include="NuGet.Client" Version="4.0.0" />
28-
<PackageReference Include="NuGet.Packaging" Version="4.0.0" />
29-
<PackageReference Include="NuGet.ProjectManagement" Version="4.0.0" />
30-
</ItemGroup>
31-
<ItemGroup>
17+
<ItemGroup>
18+
<PackageReference Include="GitInfo" Version="1.*" />
19+
<PackageReference Include="Microsoft.Build" Version="14.3.0" />
20+
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="14.3.0" />
21+
<PackageReference Include="Newtonsoft.Json" Version="6.0.8" />
22+
<PackageReference Include="MSBuilder.Dump" Version="*" />
23+
<PackageReference Include="MSBuilder.DumpItems" Version="*" />
24+
<PackageReference Include="MSBuilder.Introspect" Version="*" />
25+
<PackageReference Include="xunit" Version="2.2.0" />
26+
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
27+
<PackageReference Include="NuGet.Client" Version="4.0.0" />
28+
<PackageReference Include="NuGet.Packaging" Version="4.0.0" />
29+
<PackageReference Include="NuGet.ProjectManagement" Version="4.0.0" />
30+
</ItemGroup>
31+
<ItemGroup>
3232
<None Include="NuGet.Build.Packaging.Tests.targets" />
3333
<Content Include="Scenarios\given_a_custom_build_project\Readme.txt" />
3434
<Content Include="Scenarios\given_duplicate_package_files\a.csproj" />
@@ -124,6 +124,7 @@
124124
<Compile Include="ReadLegacyJsonDependenciesTests.cs" />
125125
<Compile Include="ReadLegacyConfigDependenciesTests.cs" />
126126
<Content Include="Scenarios\given_a_packaging_project_with_reference_assembly\b\MyClass.cs" />
127+
<Compile Include="TargetsTests.cs" />
127128
<Compile Include="UtilitiesTests.cs" />
128129
<Compile Include="Utilities\FrameworkAssemblyReferenceComparer.cs" />
129130
<Compile Include="Utilities\ManifestContentFilesComparer.cs" />
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System.Collections.Generic;
2+
using Microsoft.Build.Evaluation;
3+
using Xunit;
4+
5+
namespace NuGet.Build.Packaging
6+
{
7+
public class TargetsTests
8+
{
9+
[Fact]
10+
public void IncludeFrameworkReferencesInPackage_defaults_to_false_for_build_primary_output()
11+
{
12+
var project = new Project("NuGet.Build.Packaging.targets", new Dictionary<string, string>
13+
{
14+
{ "PrimaryOutputPackageFileKind", "build" }
15+
}, "14.0");
16+
17+
Assert.Equal("false", project.GetPropertyValue("IncludeFrameworkReferencesInPackage"));
18+
}
19+
20+
[Fact]
21+
public void IncludeFrameworkReferencesInPackage_defaults_to_false_for_tool_primary_output()
22+
{
23+
var project = new Project("NuGet.Build.Packaging.targets", new Dictionary<string, string>
24+
{
25+
{ "PrimaryOutputPackageFileKind", "tool" }
26+
}, "14.0");
27+
28+
Assert.Equal("false", project.GetPropertyValue("IncludeFrameworkReferencesInPackage"));
29+
}
30+
31+
[Fact]
32+
public void IncludeFrameworkReferencesInPackage_defaults_to_false_for_tools_primary_output()
33+
{
34+
var project = new Project("NuGet.Build.Packaging.targets", new Dictionary<string, string>
35+
{
36+
{ "PrimaryOutputPackageFileKind", "tools" }
37+
}, "14.0");
38+
39+
Assert.Equal("false", project.GetPropertyValue("IncludeFrameworkReferencesInPackage"));
40+
}
41+
42+
[Fact]
43+
public void IncludeFrameworkReferencesInPackage_defaults_to_true_for_default_primary_output()
44+
{
45+
var project = new Project("NuGet.Build.Packaging.targets", new Dictionary<string, string>
46+
{
47+
}, "14.0");
48+
49+
Assert.Equal("true", project.GetPropertyValue("IncludeFrameworkReferencesInPackage"));
50+
}
51+
52+
[Fact]
53+
public void IncludeFrameworkReferencesInPackage_defaults_to_false_for_compat_istool()
54+
{
55+
var project = new Project("NuGet.Build.Packaging.targets", new Dictionary<string, string>
56+
{
57+
{ "IsTool", "true" }
58+
}, "14.0");
59+
60+
Assert.Equal("false", project.GetPropertyValue("IncludeFrameworkReferencesInPackage"));
61+
}
62+
63+
[Fact]
64+
public void PackOnBuild_defaults_to_true_for_compat_GeneratePackageOnBuild_true()
65+
{
66+
var project = new Project("NuGet.Build.Packaging.targets", new Dictionary<string, string>
67+
{
68+
{ "GeneratePackageOnBuild", "true" }
69+
}, "14.0");
70+
71+
Assert.Equal("true", project.GetPropertyValue("PackOnBuild"));
72+
}
73+
74+
75+
}
76+
}

0 commit comments

Comments
 (0)