Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Issues with PackTask and packing NuSpec #4250
Although PackTask supports passing in a nuspec file directly, this task is still very hard to use and is pretty buggy. Here are some issues I encountered while trying to replace 'dotnet nuget pack *.nuspec' with 'PackTask' (4.0.0-rc3-2193).
Properties replacement = how to specify variable properties? NuGet.exe supports variable substitution.
NuspecOutputPath = Causes NRE if unset, but doesn't make sense in this context.
These properties, when set on the PackTask, should override what is in the nuspec but do not.
Combined with the lack of property replacement, it makes it impossible to pack a nuspec that is defined with variable substitution for required metadata. E.g.
<id>$id$</id> <version>$version</version> <description>$id$</description>
@natemcmaster PackItem is supposed to be a csproj, it can be left blank and it will infer the csproj if you are in the same directory. The only thing that changes when packing with a nuspec file is /p:NuspecFile is passed .
NuspecOutputPath and RestoreOutputPath pick up default values from the csproj file based on the value of BaseIntermediateOutputPath
Can you attach a repro project where you are repro'ing these issues?
I'm not using csproj. I'm trying to write an MSBuild target for our build system. See https://github.com/aspnet/Common/tree/119fa62786b414157a11a21f1aa8b586fe355d44/shared.
Instead of shelling out to NuGet.exe, I'm trying to use PackTask directly.
For more context, here is the code (that worked in 4.0.0-rc2) that I'm trying to replace with RC3 bits:
<ItemGroup> <Packages Include="$([System.IO.Directory]::GetDirectories("$(MSBuildThisFileDirectory)", '*.Sources'))" /> </ItemGroup> <Exec Command="dotnet nuget pack "$(MSBuildThisFileDirectory)sources.nuspec" --base-path "%(Packages.Identity)" --version $(Version) --output-directory "$(OutputPath)" --properties "id=%(Packages.FileName)%(Packages.Extension)"" />
Here's the nuspec:
<?xml version="1.0" encoding="utf-8"?> <package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> <metadata> <id>$id$</id> <version>$version$</version> <authors>Microsoft</authors> <owners>Microsoft</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>$id$</description> <contentFiles> <files include="contentFiles/cs/**/*.cs" buildAction="Compile" /> <files include="**/*.resx" buildAction="EmbeddedResource" /> </contentFiles> </metadata> <files> <file src="**\*.resx" target="contentFiles/any/netstandard1.0/" /> <file src="**\*.cs" target="contentFiles/cs/netstandard1.0/" /> </files> </package>
I would have expected to replace shelling out to NuGet.exe with something like this:
<PackTask NuspecFile="myfile.nuspec" PackageVersion="$(Version)" PackageOutputPath="$(ArtifactsPath)" Properties="var_name=var_value" />
But as I tried do this, I ran into the issue described above.
@natemcmaster This won't work if you call the PackTask directly. You need to still call dotnet pack as a command and pass in /p:NuspecFile="path to nuspec file" .
Most likely the current version of dotnet you are using doesn't have the updated nuget which supports packing from nuspec file, but we are in the process of creating one and you should be able to use it tomorrow.
@natemcmaster yes. you should only use dotnet pack as the entry point for anything related to pack. i have identified some of the issues that you are facing here, and we are trying to determine at this point whether we can fix them for 4.0.0-RTM or whether we need to put them in the next milestone.