When using NuGet Pack, can I specify a package name without a nuspec file?

I am trying to create a nuget package for a .csproj file, but I want the package name to be different from the csroj file (by default it), and I do not want to specify the .nuspec file. Is there any way to do this? I can only see the version name override option in the command line options, and not the package name override option.

I do it in TeamCity, but it doesn’t matter. I think I need to pass additional parameters to the NuGet pack command?

Thanks,

+8
c # nuget teamcity
source share
4 answers

The Nuget command line provides no option to directly change the name. http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command

If you want to distinguish between the project name and nuget, you will have to prepare and edit the custom nuspec file. You can also do this manually after creating the package, using, for example, NuGetPackage Explorer.

+2
source share

The Nuget property argument is what you are looking for.

If your .nuspec file uses a placeholder, you can pass a value to it through the Properties argument. From nuget docs :

Properties Specifies a list of token pairs = value, separated by a semicolon, where each occurrence of $ token $ in the .nuspec file will be replaced by the specified value. Values ​​can be quoted strings.

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

+1
source share

From NuGet 4.0, you can now specify the 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 details.

0
source share

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

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

All Articles