14

I'm trying to create a NuGet Package via command line and I can't seem to figure out how to set Description, Author, Title, Summary, releaseNotes, and Owner. The package creates successfully it just gives me this warning:

WARNING: Description was not specified. Using 'Description'.
WARNING: Author was not specified. Using 'User'.

Here's my command:

NuGet.exe pack "<MyProjectPath>.csproj" -OutputDirectory "<MyOutputDirectory>" -Properties Configuration=release;Description="MyDescription";Authors="MeMeMe...MeToo";Title="MyTitle";Summary="MySummary";releaseNotes="MyChanges;"Owners="MyCompany"

I'm not sure if this matters but I'm using the NuGet.exe that came from the "CredentialProviderBundle.zip" file downloaded from Visual Studio Team Services.

LorneCash
  • 1,446
  • 2
  • 16
  • 30
  • 1
    Do you specify AssemblyCompany and AssemblyDescription values in AssemblyInfo.cs file? If so, could you reproduce that issue with new project? – starian chen-MSFT Nov 15 '16 at 03:00
  • I created a new class library project. I did not modify the AssemblyInfo.cs file at all. AssemblyCompany and AssemblyDescription are both an empty string. Same exact problem. – LorneCash Nov 15 '16 at 03:12
  • I then specified AssemblyCompany and AssemblyDescription and they are now populated in the nuspec file and there were no warnings but they are populated with the values from the AssemblyInfo.cs and NOT the values I specified in the the command line. Also summary and releaseNotes were not added to the nuspec file. – LorneCash Nov 15 '16 at 03:18
  • That is the expect behavior. You need to generate .nuspec file first (nugget spec), then create package if you want to specify the values in -properties. You can add a new token for releaseNotes (replace default releaseNotes section)$releaseNotes$ in nuspec file. – starian chen-MSFT Nov 15 '16 at 05:35

6 Answers6

15

In case this helps someone else, a stupid reason for getting a "Description is required" error: I had not rebuilt my project since I added a description to my AssemblyInfo.

I'd defined a nuspec file in my project directory with a <description>$description$</description> token. When I ran

nuget pack MyProject.csproj

I saw a "Description is required" error, even though my AssemblyInfo contained [assembly: AssemblyDescription("A DESCRIPTION.")]...

... because although you pack the .csproj, it is your most recent build that is actually packaged by Nuget. d'oh.

tessafyi
  • 2,273
  • 2
  • 19
  • 28
  • Also to address missing author message one can use following assembly attribute: `[assembly: AssemblyCompany("an author")]`. – stop-cran Jun 13 '18 at 07:15
  • Setting the AssemblyDescription and rebuilding the project before running nuget pack did the trick. Thanks a lot! – Mladen B. Jan 09 '19 at 15:25
  • Today I found out that the `$xyz$` in the .nuspec files are placeholders. (Yes, it's obvious to me now!) You can define arbitrary placeholders in the .nuspec files and have `nuget.exe` apply values you provide as `-Properties xyz="value"` arguments. In other words, `-Properties description="My description!"` works when your .nuspec file specifies `$description$`. – Sigurd Garshol Oct 21 '22 at 10:49
13

There's actually almost nothing wrong with the command.

It is not possible to do what the question asks without some prerequisites.

  1. There must be a *.nuspec file in the same directory as the *.csproj with the same exact name.
  2. The *.nuspec file must contain all the elements you are trying to set via command line
  3. All elements that will be populated via command line must contain a token in the form "$tokenName$"
  4. In the command line you must not specify the *.nuspec element name but rather the value contained between the dollar signs (AKA the token name)
  5. The token name may be the same as the element name for all the properties listed in the question with the exception of the Description element. The Description element's token must NOT be named "Description". "Desc" works perfectly fine here. (This is why I said ALMOST nothing wrong with the command listed in the question)

Here's an example of a *.nuspec file for this specific example:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
    <metadata>
        <id>$Id$</id>
        <version>$Version$</version>
        <title>$Title$</title>
        <authors>$Authors$</authors>
        <owners>$Owners$</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>$Desc$</description>
        <summary>$Summary$</summary>
        <releaseNotes>$ReleaseNotes$</releaseNotes>
        <copyright>Copyright ©  2016</copyright>
        <dependencies />
    </metadata>
</package>

The Id and Version don't need to have tokens because they will automatically be overwritten either way, but it doesn't hurt.

Here's the command line you should use with the *.nuspec file as specified above:

NuGet.exe pack "<MyProjectPath>.csproj" -OutputDirectory "<MyOutputDirectory>" -Properties Configuration=release;Desc="MyDescription";Authors="MeMeMe...MeToo";Title="MyTitle";Summary="MySummary";ReleaseNotes="MyChanges;"Owners="MyCompany"
LorneCash
  • 1,446
  • 2
  • 16
  • 30
  • 7
    But what if you don't want to use a nuspec file? I prefer just packing from csproj, and some versions of nuget I've used would pick up the description from the AssemblyInfo, but others do not. I prefer packing from csproj because then I don't have to update the nuspec, which can grow very tedious when you have changing dependency versions. Packing from csproj just updates dependencies versions automatically. – Kris Coleman Apr 26 '17 at 23:18
  • @KrisColeman did you ever find a solution? I recently move to .Net5 but am finding that the build's "NuGet pack" command no longer takes the attributes from assemblyinfo. I have a SO question here: https://stackoverflow.com/questions/69676935/how-to-get-nuget-package-attributes-from-built-assembly – Andrew Stephens Oct 25 '21 at 08:07
  • I couldn't find a way to get it working without the nuspec file, that's why i went this route. I was using .Net Framework though. If you do find a way be sure to post your answer. If love to have that option too. – LorneCash Oct 26 '21 at 17:50
  • @AndrewStephens No, I ended up using the .nuspec file but I just read in the variables from the csproj so I don't need to update the nuspec file and it remains "untouched" between commits. – Kris Coleman Nov 04 '21 at 16:05
3

For me unblocking nuget.exe did the trick. As of NuGet 5.7 this seems to be necessary.

Unblock nuget.exe

  • I can confirm this was necessary for nuget.exe to use the csproj file properties in the resulting packages when using nuget.exe pack. – David Anderson Oct 01 '21 at 18:47
1

I know this is fairly old, but I've been struggling with this issue today for a while. I was running

nuget pack SomeRandom.csproj -Properties Configuration=Release

and I was getting 'Description is required' error.

I ended up then deleting the nuspec file and getting nuget to create a new one by running

nuget spec SomeRandom.csproj

Then when I ran nuget pack it worked fine. Weird, but could help someone.

matt_lethargic
  • 2,706
  • 1
  • 18
  • 33
0

For a similar, but related issue:

When setting these properties through the .csproj file of a .NET Core project, the warnings can be avoided by using:

dotnet pack

instead of

nuget pack
Ryan Naccarato
  • 674
  • 8
  • 12
-1

Just to add to this post, since neither of these fully helped me, run the command

nuget pack

This will create a Package.nuspec file for you at the base of your solution. Once this is done, you must rename the file to NameOfProject.nuspec. So if my project is called GameEngine.csproj then I will rename my nuspec file to GameEnginer.csproj. Then, move this file into the same folder that the .csproj is located (NOT the debug/release folder, just the basic folder containing all your handwritten code files). Then go ahead and run

nuget pack RelativePathOfNameOfProject.csproj

So if I wanted to hit my GameEngine.csproj the command would look something like

nuget pack .\GameEngine\GameEngine.csproj

Since my folder structure looks something like:

root/
├── Folder1/
├── Folder2/
├── GameEngine/
│   ├── bin/
│   ├── obj/
│   ├── Properties/
│   ├── Class1.cs
│   ├── Class2.cs
│   ├── GameEngine.nuspec
│   └── GameEngine.csproj
├── packages/
└── GameEngine.sln/

Hopefully between these answers, you can figure it out :)

Manny Villa
  • 324
  • 2
  • 4