Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with PackTask and packing NuSpec #4250

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

Issues with PackTask and packing NuSpec #4250

natemcmaster opened this issue Jan 10, 2017 · 8 comments

Comments

@natemcmaster
Copy link

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
Copy link
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?

@natemcmaster
Copy link
Author

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
Copy link
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
Copy link
Author

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
Copy link
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.

@natemcmaster
Copy link
Author

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
Copy link
Contributor

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

@rrelyea
Copy link
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
Projects
None yet
Development

No branches or pull requests

4 participants