Issues with PackTask and packing NuSpec #4250

Closed
natemcmaster opened this Issue Jan 10, 2017 · 8 comments

Comments

Projects
None yet
4 participants
@natemcmaster

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).

Unclear usage:
PackItem = This is required, but when packing a nuspec, what should this be set to?

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.
RestoreOutputPath = 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.
PackageVersion
PackageId
Description

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>

cc @rohit21agrawal

@rohit21agrawal

This comment has been minimized.

Show comment
Hide comment
@rohit21agrawal

rohit21agrawal Jan 10, 2017

Contributor

@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?

Contributor

rohit21agrawal commented Jan 10, 2017

@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?

@natemcmaster

This comment has been minimized.

Show comment
Hide comment
@natemcmaster

natemcmaster Jan 10, 2017

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(&quot;$(MSBuildThisFileDirectory)&quot;, '*.Sources'))" />
    </ItemGroup>
    <Exec Command="dotnet nuget pack
&quot;$(MSBuildThisFileDirectory)sources.nuspec&quot;
--base-path &quot;%(Packages.Identity)&quot;
--version $(Version)
--output-directory &quot;$(OutputPath)&quot;
--properties &quot;id=%(Packages.FileName)%(Packages.Extension)&quot;"
        />

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.

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(&quot;$(MSBuildThisFileDirectory)&quot;, '*.Sources'))" />
    </ItemGroup>
    <Exec Command="dotnet nuget pack
&quot;$(MSBuildThisFileDirectory)sources.nuspec&quot;
--base-path &quot;%(Packages.Identity)&quot;
--version $(Version)
--output-directory &quot;$(OutputPath)&quot;
--properties &quot;id=%(Packages.FileName)%(Packages.Extension)&quot;"
        />

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.

@rohit21agrawal

This comment has been minimized.

Show comment
Hide comment
@rohit21agrawal

rohit21agrawal Jan 10, 2017

Contributor

@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.

Contributor

rohit21agrawal commented Jan 10, 2017

@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

This comment has been minimized.

Show comment
Hide comment
@natemcmaster

natemcmaster Jan 10, 2017

This won't work if you call the PackTask directly.

To clarify, is it not working because PackTask should be used directly at all?

This won't work if you call the PackTask directly.

To clarify, is it not working because PackTask should be used directly at all?

@rohit21agrawal rohit21agrawal added this to the 4.0 RTM milestone Jan 12, 2017

@rohit21agrawal

This comment has been minimized.

Show comment
Hide comment
@rohit21agrawal

rohit21agrawal Jan 12, 2017

Contributor

@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.

Contributor

rohit21agrawal commented Jan 12, 2017

@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.

@natemcmaster

This comment has been minimized.

Show comment
Hide comment
@natemcmaster

natemcmaster Jan 12, 2017

Spoke with @rohit21agrawal in person and tried some of the private builds he was working on. They seem to fix the issues we are having. To move ASP.NET Core's build forward, we need fixes for RTM.

Spoke with @rohit21agrawal in person and tried some of the private builds he was working on. They seem to fix the issues we are having. To move ASP.NET Core's build forward, we need fixes for RTM.

@rohit21agrawal

This comment has been minimized.

Show comment
Hide comment
@rohit21agrawal

rohit21agrawal Jan 12, 2017

Contributor

@rrelyea any chance we can try this for RTM ? I am ready to send out a PR for this.

Contributor

rohit21agrawal commented Jan 12, 2017

@rrelyea any chance we can try this for RTM ? I am ready to send out a PR for this.

@rrelyea

This comment has been minimized.

Show comment
Hide comment
@rrelyea

rrelyea Jan 13, 2017

Contributor

Let's review the design on the team. Your current design:
nuget.exe pack -properties foo=bar;bar=tom

msbuild /t:pack /p:NuspecFile=input.nuspec /p:nuspecproperties=\"foo=bar;bar=tom\"

Contributor

rrelyea commented Jan 13, 2017

Let's review the design on the team. Your current design:
nuget.exe pack -properties foo=bar;bar=tom

msbuild /t:pack /p:NuspecFile=input.nuspec /p:nuspecproperties=\"foo=bar;bar=tom\"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment