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

Commit 1886901

Browse files
kzuadalon
authored andcommitted
Support simplified authoring projects
By moving some target dependencies under the condition that IncludeOutputsInPackage is true, we allow simple .proj files without the MS.Common targets to also participate in nuget packing with minimal configuration, namely setting IncludeOutputsInPackage=false and IncludeFrameworkReferencesInPackage=true.
1 parent bae4b02 commit 1886901

5 files changed

Lines changed: 62 additions & 11 deletions

File tree

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,14 @@ Copyright (c) .NET Foundation. All rights reserved.
202202
<GetPackageContentsDependsOn>
203203
$(GetPackageContentsDependsOn);
204204
GetPackageTargetPath;
205-
AssignProjectConfiguration;
206-
_SplitProjectReferencesByFileExistence;
207-
_SplitProjectReferencesByIsNuGetized;
208-
AllProjectOutputGroups;
209205
ReadLegacyDependencies;
210206
</GetPackageContentsDependsOn>
211-
<!-- Only collect referenced projects' outputs if we need to include them -->
212207
<GetPackageContentsDependsOn Condition="'$(IncludeOutputsInPackage)' == 'true'">
213208
$(GetPackageContentsDependsOn)
209+
AssignProjectConfiguration;
210+
_SplitProjectReferencesByFileExistence;
211+
_SplitProjectReferencesByIsNuGetized;
212+
AllProjectOutputGroups;
214213
_GetReferenceAssemblyTargetPaths;
215214
</GetPackageContentsDependsOn>
216215
</PropertyGroup>

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<ItemGroup>
1919
<None Include="project.json" />
2020
<None Include="NuGet.Build.Packaging.Tests.targets" />
21+
<Content Include="Scenarios\given_a_custom_build_project\Readme.txt" />
2122
<Content Include="Scenarios\given_a_library_with_content\content-with-include-true.txt" />
2223
<Content Include="Scenarios\given_a_library_with_content\content-with-include-false.txt" />
2324
<Content Include="Scenarios\given_a_library_with_content\none-with-include-false.txt" />
@@ -28,9 +29,8 @@
2829
<Content Include="Scenarios\given_a_library_with_content\Resources\drawable-xhdpi\Icon.png" />
2930
<Content Include="Scenarios\given_a_library_with_content\Resources\drawable-xxhdpi\Icon.png" />
3031
<Content Include="Scenarios\given_a_library_with_content\Resources\drawable-xxxhdpi\Icon.png" />
31-
<None Include="Scenarios\given_a_packaging_project\a.nuproj">
32-
<SubType>Designer</SubType>
33-
</None>
32+
<None Include="Scenarios\given_a_custom_build_project\build.proj" />
33+
<None Include="Scenarios\given_a_packaging_project\a.nuproj" />
3434
<Content Include="Scenarios\given_a_packaging_project\b.sln" />
3535
<Content Include="Scenarios\given_a_packaging_project\b\b.csproj" />
3636
<Content Include="Scenarios\given_a_packaging_project\c.csproj" />
@@ -50,9 +50,7 @@
5050
<Content Include="Scenarios\given_a_complex_pack\c.csproj" />
5151
<Content Include="Scenarios\given_a_complex_pack\d.csproj" />
5252
<Content Include="Scenarios\given_a_complex_pack\e.csproj" />
53-
<Content Include="Scenarios\given_a_library_with_non_nugetized_reference\a.csproj">
54-
<SubType>Designer</SubType>
55-
</Content>
53+
<Content Include="Scenarios\given_a_library_with_non_nugetized_reference\a.csproj" />
5654
<Content Include="Scenarios\given_a_multi_platform_solution\android\forms.android.csproj" />
5755
<Content Include="Scenarios\given_a_multi_platform_solution\common\common.csproj" />
5856
<Content Include="Scenarios\given_a_multi_platform_solution\forms.sln" />
@@ -90,6 +88,7 @@
9088
<DependentUpon>Builder.cs</DependentUpon>
9189
</Compile>
9290
<Compile Include="GetApiIntersectTargetPathsTests.cs" />
91+
<Compile Include="given_a_custom_build_project.cs" />
9392
<Compile Include="given_a_packaging_project.cs" />
9493
<Compile Include="given_a_multi_platform_solution.cs" />
9594
<Compile Include="given_a_library_with_content.cs" />

src/Build/NuGet.Build.Packaging.Tests/Scenarios/given_a_custom_build_project/Readme.txt

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<!-- This will be the right path when we run from xunit in the bin/$(Configuration) folder -->
5+
<NuGetTargetsPath Condition="'$(NuGetTargetsPath)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), NuGet.Build.Packaging.props))</NuGetTargetsPath>
6+
<!-- This will be the right path when we run from MSBuild from the source location inside the tests project -->
7+
<NuGetTargetsPath Condition="!Exists('$(NuGetTargetsPath)\NuGet.Build.Packaging.props')">$(MSBuildThisFileDirectory)..\..\..\NuGet.Build.Packaging.Tasks\bin\Debug</NuGetTargetsPath>
8+
</PropertyGroup>
9+
<Import Project="$(NuGetTargetsPath)\NuGet.Build.Packaging.props" />
10+
11+
<PropertyGroup>
12+
<PackageId>build</PackageId>
13+
<PackageVersion>1.0.0</PackageVersion>
14+
<Authors>NuGet</Authors>
15+
<Description>Package for '$(MSBuildProjectName)' project.</Description>
16+
<IncludeOutputsInPackage>false</IncludeOutputsInPackage>
17+
<IncludeFrameworkReferencesInPackage>true</IncludeFrameworkReferencesInPackage>
18+
</PropertyGroup>
19+
<ItemGroup>
20+
<PackageFile Include="Readme.txt" />
21+
</ItemGroup>
22+
<Import Project="$(NuGetTargetsPath)\NuGet.Build.Packaging.targets" />
23+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Linq;
2+
using Microsoft.Build.Execution;
3+
using Xunit;
4+
using Xunit.Abstractions;
5+
6+
namespace NuGet.Build.Packaging
7+
{
8+
public class given_a_custom_build_project
9+
{
10+
ITestOutputHelper output;
11+
12+
public given_a_custom_build_project(ITestOutputHelper output)
13+
{
14+
this.output = output;
15+
}
16+
17+
[Fact]
18+
public void when_packing_then_can_include_content()
19+
{
20+
var result = Builder.BuildScenario(nameof(given_a_custom_build_project));
21+
22+
Assert.Equal(TargetResultCode.Success, result.ResultCode);
23+
24+
Assert.Contains(result.Items, item => item.Matches(new
25+
{
26+
PackagePath = "Readme.txt",
27+
}));
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)