-
Notifications
You must be signed in to change notification settings - Fork 265
Description
NuGet Product Used
dotnet.exe, MSBuild.exe
Product Version
dotnet.exe version10.0.0 , MSBuild 17.14.23+b0019275e (.NET Framework)
Worked before?
No response
Impact
It's more difficult to complete my work
Repro Steps & Context
<Project Sdk="Microsoft.NET.Sdk"> <!-- test.csproj -->
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
<IncludeBuildOutput>true</IncludeBuildOutput>
<IncludeBuiltProjectOutputGroup>false</IncludeBuiltProjectOutputGroup>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>00_proj</PackageId>
<PackageVersion>2.0.0.0</PackageVersion>
<PackageTags>tagA;tagB</PackageTags>
<NuspecFile>test.nuspec</NuspecFile>
</PropertyGroup>
<ItemGroup>
<None Remove="test.nuspec" />
</ItemGroup>
<Target Name="write_OutputPackItems" AfterTargets="_GetOutputItemsFromPack" >
<WriteLinesToFile File="obj/_OutputPackItems.txt" Lines="@(_OutputPackItems)" Overwrite="true" Encoding="UTF-8" />
</Target>
</Project><?xml version="1.0" encoding="utf-8"?> <!-- test.nuspec -->
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>00_nusp</id>
<version>4.0.0.0</version>
<authors>Unit Test</authors>
<description>Sample Description</description>
<language>en-US</language>
</metadata>
</package>dotnet buildA file named 00_nusp.4.0.0.nupkg is generated as a result of the build,
And a log file named _OutputPackItems.txt is also created.
What I expected
The file name output in _OutputPackItems.txt is expected to be 00_nusp.4.0.0.nupkg.
What I got
However, the file name in _OutputPackItems.txte is 00_proj.2.0.0.nupkg, not 00_nusp.4.0.0.nupkg.
Verbose Logs
Description
There is no reliable way to obtain the correct name of the nupkg file generated by Pack when the project file contains either the NuspecFile property or NuspecProperties.
Why this is a problem
I want to apply an Authenticode signature to the nupkg file generated by msbuild (i.e., call dotnet nuget sign when a release build succeeds, or sign an existing nupkg file).
However, I cannot determine the correct file to sign, so the signing process fails.
If the version is generated dynamically (e.g., based on a timestamp), the nupkg file path cannot be known in advance.
Current behavior of Pack
When the project file specifies a NuspecFile property, the metadata.id of the referenced nuspec file becomes the base name of the nupkg file.
If Nuspec properties includes a version value, it overrides the metadata.version in the nuspec file referenced by NuspecFile.
The generated file name is created dynamically inside NuGet.Commands.PackCommandRunner, but it is not exposed as a task output.
The only way to discover it is through the log output: *
_packArgs.Logger.Log(
PackagingLogMessage.CreateMessage(
string.Format(CultureInfo.CurrentCulture, Strings.Log_PackageCommandSuccess, outputPath),
LogLevel.Minimal));
Problem
Before the Pack target runs, the _GetOutputItemsFromPack target generates the file path, and NuGet.Build.Tasks.Pack.GetPackOutputItemsTask computes the expected file name in advance.
However, the Pack target receives the PackageId and PackageVersion from the project properties and uses them directly to construct the filenames.
This task receives PackageId and PackageVersion from the project properties and uses them directly to construct the file name.
Result
The file name produced by _GetOutputItemsFromPack does not match the actual file name generated by Pack.
When Pack is executed again, _CleanPackFiles attempts to delete the previously generated file, but the deletion fails because the file name differs.
Fix and Test Code
I have uploaded the fix I created and the corresponding test code to this branch.