Skip to content

Commit 0343ad1

Browse files
committed
Fix Nuget package file name that generated by _GetTargetFrameworksOutput target in Nuget.Build.Tasks.Pack.targets.
1 parent 4c1e976 commit 0343ad1

5 files changed

Lines changed: 438 additions & 14 deletions

File tree

NuGet.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ EndProject
161161
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.XPlat.FuncTest", "test\NuGet.Core.FuncTests\NuGet.XPlat.FuncTest\NuGet.XPlat.FuncTest.csproj", "{2034C981-C938-4F0F-8F3B-528B83CB8F7D}"
162162
EndProject
163163
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.Build.Tasks.Pack.Test", "test\NuGet.Core.Tests\NuGet.Build.Tasks.Pack.Test\NuGet.Build.Tasks.Pack.Test.csproj", "{8BF8279D-196F-481A-9659-488864D93D2D}"
164+
ProjectSection(ProjectDependencies) = postProject
165+
{3B96F91B-3B58-40ED-B06E-5CD133A79A63} = {3B96F91B-3B58-40ED-B06E-5CD133A79A63}
166+
EndProjectSection
164167
EndProject
165168
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.Build.Tasks.Pack", "src\NuGet.Core\NuGet.Build.Tasks.Pack\NuGet.Build.Tasks.Pack.csproj", "{16863138-7C0E-49ED-A1C8-B9165FED9920}"
166169
EndProject

src/NuGet.Core/NuGet.Build.Tasks.Pack/GetPackOutputItemsTask.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public class GetPackOutputItemsTask : Microsoft.Build.Utilities.Task
2929
[Required]
3030
public string NuspecOutputPath { get; set; }
3131

32+
public string NuspecInputFilePath { get; set; }
33+
34+
public string[] NuspecProperties { get; set; }
35+
3236
public bool IncludeSymbols { get; set; }
3337

3438
public bool IncludeSource { get; set; }
@@ -43,27 +47,41 @@ public class GetPackOutputItemsTask : Microsoft.Build.Utilities.Task
4347

4448
public override bool Execute()
4549
{
50+
var packageId = PackageId;
51+
var packageVersion = PackageVersion;
52+
53+
if (!string.IsNullOrWhiteSpace(NuspecInputFilePath))
54+
{
55+
var nuspecReader = new NuGet.Packaging.NuspecReader(NuspecInputFilePath);
56+
packageId = nuspecReader.GetId();
57+
packageVersion = nuspecReader.GetVersion().ToNormalizedString();
58+
59+
PackArgs packArgs = new PackArgs() { Version = packageVersion };
60+
PackTaskLogic.SetPackArgsPropertiesFromNuspecProperties(packArgs, MSBuildStringUtility.TrimAndExcludeNullOrEmpty(NuspecProperties), NuspecInputFilePath);
61+
packageVersion = packArgs.Version;
62+
}
63+
4664
NuGetVersion version;
47-
if (!NuGetVersion.TryParse(PackageVersion, out version))
65+
if (!NuGetVersion.TryParse(packageVersion, out version))
4866
{
4967
throw new ArgumentException(string.Format(
5068
CultureInfo.CurrentCulture,
5169
Strings.InvalidPackageVersion,
52-
PackageVersion));
70+
packageVersion));
5371
}
5472

5573
var symbolPackageFormat = PackArgs.GetSymbolPackageFormat(MSBuildStringUtility.TrimAndGetNullForEmpty(SymbolPackageFormat));
56-
var nupkgFileName = PackCommandRunner.GetOutputFileName(PackageId, version, isNupkg: true, symbols: false, symbolPackageFormat: symbolPackageFormat);
57-
var nuspecFileName = PackCommandRunner.GetOutputFileName(PackageId, version, isNupkg: false, symbols: false, symbolPackageFormat: symbolPackageFormat);
74+
var nupkgFileName = PackCommandRunner.GetOutputFileName(packageId, version, isNupkg: true, symbols: false, symbolPackageFormat: symbolPackageFormat);
75+
var nuspecFileName = PackCommandRunner.GetOutputFileName(packageId, version, isNupkg: false, symbols: false, symbolPackageFormat: symbolPackageFormat);
5876

5977
var outputs = new List<ITaskItem>();
6078
outputs.Add(new TaskItem(Path.Combine(PackageOutputPath, nupkgFileName)));
6179
outputs.Add(new TaskItem(Path.Combine(NuspecOutputPath, nuspecFileName)));
6280

6381
if (IncludeSource || IncludeSymbols)
6482
{
65-
var nupkgSymbolsFileName = PackCommandRunner.GetOutputFileName(PackageId, version, isNupkg: true, symbols: true, symbolPackageFormat: symbolPackageFormat);
66-
var nuspecSymbolsFileName = PackCommandRunner.GetOutputFileName(PackageId, version, isNupkg: false, symbols: true, symbolPackageFormat: symbolPackageFormat);
83+
var nupkgSymbolsFileName = PackCommandRunner.GetOutputFileName(packageId, version, isNupkg: true, symbols: true, symbolPackageFormat: symbolPackageFormat);
84+
var nuspecSymbolsFileName = PackCommandRunner.GetOutputFileName(packageId, version, isNupkg: false, symbols: true, symbolPackageFormat: symbolPackageFormat);
6785

6886
outputs.Add(new TaskItem(Path.Combine(PackageOutputPath, nupkgSymbolsFileName)));
6987
outputs.Add(new TaskItem(Path.Combine(NuspecOutputPath, nuspecSymbolsFileName)));

src/NuGet.Core/NuGet.Build.Tasks.Pack/PackTaskLogic.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,7 @@ public PackArgs GetPackArgs(IPackTaskRequest<IMSBuildItem> request)
7575

7676
if (!string.IsNullOrEmpty(request.NuspecFile))
7777
{
78-
if (request.NuspecProperties != null && request.NuspecProperties.Any())
79-
{
80-
packArgs.Properties.AddRange(ParsePropertiesAsDictionary(request.NuspecProperties));
81-
if (packArgs.Properties.TryGetValue("version", out var version))
82-
{
83-
packArgs.Version = version;
84-
}
85-
}
78+
SetPackArgsPropertiesFromNuspecProperties(packArgs, request.NuspecProperties, request.NuspecFile);
8679
}
8780
else
8881
{
@@ -1091,6 +1084,28 @@ private static IDictionary<string, string> ParsePropertiesAsDictionary(string[]
10911084
return dictionary;
10921085
}
10931086

1087+
internal static void SetPackArgsPropertiesFromNuspecProperties(PackArgs packArgs, string[] nuspecProperties, string nuspecInputFilePath)
1088+
{
1089+
if (!string.IsNullOrWhiteSpace(nuspecInputFilePath))
1090+
{
1091+
if (nuspecProperties != null && nuspecProperties.Any())
1092+
{
1093+
packArgs.Properties.AddRange(ParsePropertiesAsDictionary(nuspecProperties));
1094+
if (packArgs.Properties.TryGetValue("version", out var packageVersion))
1095+
{
1096+
if (!NuGetVersion.TryParse(packageVersion, out var version))
1097+
{
1098+
throw new ArgumentException(string.Format(
1099+
CultureInfo.CurrentCulture,
1100+
Strings.InvalidPackageVersion,
1101+
packageVersion));
1102+
}
1103+
packArgs.Version = version.ToNormalizedString();
1104+
}
1105+
}
1106+
}
1107+
}
1108+
10941109
private HashSet<string> InitOutputExtensions(IEnumerable<string> outputExtensions)
10951110
{
10961111
return new HashSet<string>(outputExtensions.Distinct(StringComparer.OrdinalIgnoreCase));

src/NuGet.Core/NuGet.Build.Tasks/NuGet.Build.Tasks.Pack.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ Copyright (c) .NET Foundation. All rights reserved.
111111
<GetPackOutputItemsTask
112112
PackageOutputPath="$(PackageOutputAbsolutePath)"
113113
NuspecOutputPath="$(NuspecOutputAbsolutePath)"
114+
NuspecInputFilePath="$(NuspecFile)"
115+
NuspecProperties="$(NuspecProperties)"
114116
PackageId="$(PackageId)"
115117
PackageVersion="$(PackageVersion)"
116118
IncludeSymbols="$(IncludeSymbols)"

0 commit comments

Comments
 (0)