12

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
  • 4,545
  • 13
  • 51
  • 85

5 Answers5

6

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.

willy
  • 199
  • 3
3

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

Kal
  • 1,887
  • 12
  • 16
  • 2
    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. – Suamere May 09 '18 at 22:09
3

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

STW
  • 44,917
  • 17
  • 105
  • 161
2

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>
masih
  • 598
  • 1
  • 6
  • 10
0

As I did not see any updated solution. In the .csproj you can specify the PackageId

<PackageId>Different.Name.Than.Csproj</PackageId>

MS ref.

Marco Medrano
  • 2,530
  • 1
  • 21
  • 35