11
votes

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,

4

4 Answers

4
votes

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.

3
votes

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

2
votes

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.

2
votes

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>