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

Commit 4c64e31

Browse files
authored
Merge pull request #122 from kzu/dev
Minor improvements and fixes
2 parents 1fc24da + a2b2c58 commit 4c64e31

10 files changed

+212
-59
lines changed

src/Build/NuGet.Build.Packaging.Tasks/AssignPackagePath.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,15 @@ ITaskItem EnsurePackagePath(ITaskItem file, IDictionary<string, string> kindMap)
125125
// P2P references)
126126
var targetPath = file.GetMetadata("TargetPath");
127127
if (string.IsNullOrEmpty(targetPath))
128-
targetPath = file.GetMetadata("FileName") + file.GetMetadata("Extension");
128+
{
129+
targetPath = kind == PackageItemKind.None ?
130+
// For None, preserve the relative dir.
131+
file.GetMetadata("RelativeDir") + file.GetMetadata("FileName") + file.GetMetadata("Extension") :
132+
file.GetMetadata("FileName") + file.GetMetadata("Extension");
133+
}
129134

130-
// None files or those for which we know no mapping, go straight to the root folder of the package.
135+
// None files or those for which we know no mapping, go straight to the root folder of the package,
136+
// respecting their RelativeDir.
131137
// This allows custom packaging paths such as "workbooks", "docs" or whatever, which aren't prohibited by
132138
// the format.
133139
var packagePath = string.IsNullOrEmpty(packageFolder) ?

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ Copyright (c) .NET Foundation. All rights reserved.
1111
-->
1212
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1313
<PropertyGroup>
14-
<!--<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
14+
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
1515
<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>-->
16+
<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>
1917

2018
<TargetExt>.nupkg</TargetExt>
2119

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--
2+
***********************************************************************************************
3+
Microsoft.NuGet.Build.Packaging.Compatibility.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+
<PropertyGroup>
15+
<PackOnBuild Condition="'$(GeneratePackageOnBuild)' == 'true'">true</PackOnBuild>
16+
<PrimaryOutputPackageFileKind Condition="'$(IsTool)' == 'true'">tool</PrimaryOutputPackageFileKind>
17+
</PropertyGroup>
18+
19+
</Project>

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,27 @@
88
<OutputType>Exe</OutputType>
99
<TargetExt>.dll</TargetExt>
1010
<StartupObject>NuGet.Build.Packaging.Program</StartupObject>
11+
<PackOnBuild Condition="'$(PackOnBuild)' == '' And '$(Configuration)' == 'Release'">true</PackOnBuild>
12+
<PackageOutputPath Condition="'$(PackageOutputPath)' == ''">..\..\..\out</PackageOutputPath>
1113
</PropertyGroup>
1214
<ItemGroup>
1315
<Reference Include="System" />
1416
<Reference Include="System.Core" />
1517
</ItemGroup>
16-
<ItemGroup>
17-
<PackageReference Include="Costura.Fody" Version="1.3.3" />
18-
<PackageReference Include="Fody" Version="1.29.4" />
19-
<PackageReference Include="GitInfo" Version="1.*" />
20-
<PackageReference Include="netfx-System.StringResources" Version="*" />
21-
<PackageReference Include="Microsoft.Build" Version="14.3.0" />
22-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="14.3.0" />
23-
<PackageReference Include="MSBuilder.ThisAssembly.Project" Version="0.3.3" />
24-
<PackageReference Include="Newtonsoft.Json" Version="6.0.8" />
25-
<PackageReference Include="NuGet.Client" Version="4.0.0" />
26-
<PackageReference Include="NuGet.Packaging" Version="4.0.0" />
27-
<PackageReference Include="NuGet.ProjectManagement" Version="4.0.0" />
28-
</ItemGroup>
29-
<ItemGroup>
18+
<ItemGroup>
19+
<PackageReference Include="Costura.Fody" Version="1.3.3" PrivateAssets="all" />
20+
<PackageReference Include="Fody" Version="1.29.4" PrivateAssets="all" />
21+
<PackageReference Include="GitInfo" Version="1.*" PrivateAssets="all" />
22+
<PackageReference Include="netfx-System.StringResources" Version="*" PrivateAssets="all" />
23+
<PackageReference Include="Microsoft.Build" Version="14.3.0" PrivateAssets="all" />
24+
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="14.3.0" PrivateAssets="all" />
25+
<PackageReference Include="MSBuilder.ThisAssembly.Project" Version="0.3.3" PrivateAssets="all" />
26+
<PackageReference Include="Newtonsoft.Json" Version="6.0.8" PrivateAssets="all" />
27+
<PackageReference Include="NuGet.Client" Version="4.0.0" PrivateAssets="all" />
28+
<PackageReference Include="NuGet.Packaging" Version="4.0.0" PrivateAssets="all" />
29+
<PackageReference Include="NuGet.ProjectManagement" Version="4.0.0" PrivateAssets="all" />
30+
</ItemGroup>
31+
<ItemGroup>
3032
<Content Include="FodyWeavers.xml" />
3133
<Content Include="NuGet.Build.Packaging.props">
3234
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -47,6 +49,9 @@
4749
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4850
<SubType>Designer</SubType>
4951
</Content>
52+
<Content Include="NuGet.Build.Packaging.Compatibility.targets">
53+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
54+
</Content>
5055
<None Include="NuGet.Build.Packaging.Version.props">
5156
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5257
</None>
@@ -59,7 +64,6 @@
5964
<Content Include="GenerateReferenceAssembly.csproj">
6065
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6166
</Content>
62-
<None Include="project.json" />
6367
</ItemGroup>
6468
<ItemGroup>
6569
<ProjectReference Include="..\..\..\external\ApiIntersect\ApiIntersect\ApiIntersect.csproj">

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Copyright (c) .NET Foundation. All rights reserved.
1919
<UsingTask TaskName="NuGet.Build.Packaging.Tasks.GetApiIntersectTargetPaths" AssemblyFile="NuGet.Build.Packaging.Tasks.dll" />
2020

2121
<Import Project="NuGet.Build.Packaging.props" Condition="'$(NuGetBuildPackagingPropsImported)' == ''" />
22+
<!-- Adds compatibility targets with Pack SDK -->
23+
<Import Project="NuGet.Build.Packaging.Compatibility.targets" />
2224

2325
<PropertyGroup>
2426
<!-- The Kind of primary output (build, symbols and doc) set if IncludeOutputsInPackage = true -->
@@ -33,8 +35,11 @@ Copyright (c) .NET Foundation. All rights reserved.
3335
<!-- Whether to include @(DebugSymbolsProjectOutputGroupOutput) items in the package -->
3436
<IncludeSymbolsInPackage Condition="'$(IncludeSymbolsInPackage)' == '' and '$(IncludeOutputsInPackage)' == 'true' and '$(Configuration)' == 'Debug'">true</IncludeSymbolsInPackage>
3537
<!-- Whether to include framework references (%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}') in the package -->
38+
3639
<!-- Only default to true if the project isn't a nuget packaging project itself. -->
37-
<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>
3843

3944
<PackageRequireLicenseAcceptance Condition="'$(PackageRequireLicenseAcceptance)' == ''">false</PackageRequireLicenseAcceptance>
4045

@@ -215,7 +220,7 @@ Copyright (c) .NET Foundation. All rights reserved.
215220
</InferPackageContentsDependsOn>
216221
<GetPackageContentsDependsOn>InferPackageContents</GetPackageContentsDependsOn>
217222
</PropertyGroup>
218-
223+
219224
<Target Name="GetPackageContents" DependsOnTargets="$(GetPackageContentsDependsOn)" Returns="@(_PackageContent)">
220225
<!-- We batch depending on the IsPackaging metadata, which is only specified for referenced content
221226
if the current project is building a package, to force retargeting of the referenced content. -->
@@ -277,7 +282,7 @@ Copyright (c) .NET Foundation. All rights reserved.
277282
<Kind>None</Kind>
278283
</PackageFile>
279284

280-
<PackageFile Include="@(PackageReference)">
285+
<PackageFile Include="@(PackageReference)" Condition="'%(Identity)' != 'NuGet.Build.Packaging'">
281286
<Kind>Dependency</Kind>
282287
</PackageFile>
283288

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,19 +442,19 @@ public void when_assigning_content_file_with_additional_metadata_then_preserves_
442442
}
443443

444444
[Fact]
445-
public void when_file_has_none_kind_then_assigned_file_has_empty_package_folder()
445+
public void when_file_has_none_kind_then_assigned_file_has_empty_package_folder_and_relative_package_path()
446446
{
447447
var task = new AssignPackagePath
448448
{
449449
BuildEngine = engine,
450450
Kinds = kinds,
451451
Files = new ITaskItem[]
452452
{
453-
new TaskItem("readme.txt", new Metadata
454-
{
453+
new TaskItem(@"content\docs\readme.txt", new Metadata
454+
{
455455
{ "PackageId", "A" },
456456
{ "TargetFrameworkMoniker", ".NETFramework,Version=v4.5" },
457-
{ "Kind", "None" }
457+
{ "Kind", "None" },
458458
})
459459
}
460460
};
@@ -463,7 +463,7 @@ public void when_file_has_none_kind_then_assigned_file_has_empty_package_folder(
463463
Assert.Contains(task.AssignedFiles, item => item.Matches(new
464464
{
465465
PackageFolder = "",
466-
PackagePath = "readme.txt",
466+
PackagePath = @"content\docs\readme.txt",
467467
}));
468468
}
469469

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,18 @@ public static partial class Builder
2020
const string ToolsVersion = "14.0";
2121
#endif
2222

23-
public static BuildResult Build(string projectOrSolution, string targets, Dictionary<string, string> properties = null, ILogger logger = null)
23+
public static BuildResult Build(ProjectInstance project, string targets, Dictionary<string, string> properties = null, ILogger logger = null)
2424
{
25-
if (!Path.IsPathRooted(projectOrSolution))
26-
projectOrSolution = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, projectOrSolution);
27-
28-
if (!File.Exists(projectOrSolution))
29-
throw new FileNotFoundException($"Project or solution to build {projectOrSolution} was not found.", projectOrSolution);
25+
properties = properties ?? new Dictionary<string, string>();
3026

3127
// Without this, builds end up running in process and colliding with each other,
3228
// especially around the current directory used to resolve relative paths in projects.
3329
//Environment.SetEnvironmentVariable("MSBUILDNOINPROCNODE", "1", EnvironmentVariableTarget.Process);
3430
using (var manager = new BuildManager(Guid.NewGuid().ToString()))
3531
{
36-
properties = properties ?? new Dictionary<string, string>();
37-
38-
// If file is not a solution, build up a fake solution configuration so P2P references just work
39-
if (Path.GetExtension(projectOrSolution) != ".sln")
40-
AddSolutionConfiguration(projectOrSolution, properties);
41-
42-
var request = new BuildRequestData(projectOrSolution, properties, ToolsVersion, targets.Split(','), null);
32+
var request = new BuildRequestData(project, targets.Split(','), null);
4333
var parameters = new BuildParameters
44-
{
34+
{
4535
GlobalProperties = properties,
4636
DisableInProcNode = !Debugger.IsAttached,
4737
EnableNodeReuse = false,
@@ -61,6 +51,25 @@ public static BuildResult Build(string projectOrSolution, string targets, Dictio
6151
}
6252
}
6353

54+
public static BuildResult Build(string projectOrSolution, string targets, Dictionary<string, string> properties = null, ILogger logger = null)
55+
{
56+
if (!Path.IsPathRooted(projectOrSolution))
57+
projectOrSolution = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, projectOrSolution);
58+
59+
if (!File.Exists(projectOrSolution))
60+
throw new FileNotFoundException($"Project or solution to build {projectOrSolution} was not found.", projectOrSolution);
61+
62+
properties = properties ?? new Dictionary<string, string>();
63+
64+
// If file is not a solution, build up a fake solution configuration so P2P references just work
65+
if (Path.GetExtension(projectOrSolution) != ".sln")
66+
AddSolutionConfiguration(projectOrSolution, properties);
67+
68+
var projectInstance = new ProjectInstance(projectOrSolution, properties, ToolsVersion);
69+
70+
return Build(projectInstance, targets, properties, logger);
71+
}
72+
6473
static void AddSolutionConfiguration(string projectFile, Dictionary<string, string> properties)
6574
{
6675
var collection = new ProjectCollection(properties);

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" />

0 commit comments

Comments
 (0)