When using NuGet Pack is it possible to specify the package name without a nuspec file?

15,571

Solution 1

Nuget command line doesn't provide any option for direct name change. http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command

If you want to differ project and nuget package name you will have to prepare and edit custom nuspec file. You may also do it manually after creating package by using e.g. NuGetPackage Explorer.

Solution 2

Nuget's Properties argument is what you're looking for.

Provided your .nuspec file uses a placeholder then you can pass a value for it via the Properties argument. From the nuget docs:

Properties. Specifies a list of token=value pairs, separated by semicolons, where each occurrence of $token$ in the .nuspec file will be replaced with the given value. Values can be strings in quotation marks.

So nuget.exe -Properties id=someProject will use "someProject" for any occurance of $id$.

Solution 3

You can still use "nuget pack A.csproj" if you have a A.nuspec in which you can specify a custom package name like below (otherwise package name will be the same as project name, i.e. A):

<?xml version="1.0"?>
<package >
  <metadata>
    <id>Custom A</id>
  </metadata>
</package>

Solution 4

From NuGet 4.0 it is now possible to specify package name and other metadata as properties in your .csproj file. See https://docs.microsoft.com/en-us/nuget/guides/create-net-standard-packages-vs2017 for more information.

Share:
15,571
Lee Englestone
Author by

Lee Englestone

Lee is a passionate and innovative Developer and DevRel Lead whom excels at leadership, lateral thinking, new ideas/innovation and creating proof of concepts to realise their value. He is constantly experimenting with new technologies, exploring their benefits and introducing them to others including Augmented Reality, Machine Learning, and Artificial Intelligence. He also enjoys building useful resources for the tech community including http://VisualStudioTips.co.uk, http://XamarinARKit.com and http://TechCommunityCalendar.com You can follow him @LeeEnglestone

Updated on June 26, 2022

Comments

  • Lee Englestone
    Lee Englestone almost 2 years

    I am trying to create a nuget package for a .csproj file but want the package name to be different from the csroj file (which it is by default) and I don't want to specify a .nuspec file. Is there a way of doing this? I can only see a version name override option on the command line options and not a package name override option.

    I am doing this in TeamCity but this is besides the point. I am thinking I need to pass additional parameters to the NuGet pack command?

    Thanks,

  • Lee Englestone
    Lee Englestone over 9 years
    I thought I might have to resort to using nuspec files :-(
  • Suamere
    Suamere almost 6 years
    This is only for .NET Standard. I currently don't know anybody using .NET Standard, but either way, this is a TeamCity question, not Visual Studio, Project-Type Specific.