3
votes

I want to add Tags for a nuget package. I do NOT want to use a separate .nuspec file (maintenance), I'm only using the csproj for packing.

I've tried setting it using nuget pack -Properties Tags=demo but that doesn't seem to work..?

I'm trying to solve a bigger problem to create some traceability using the commit id from the build in the tags? (on VSTS using Build.SourceVersion)

References:

3
Editing the csproj is ok but should hold placeholders like $tags$grmbl
It appears that some metadata can only be set using a nuspec file???grmbl

3 Answers

9
votes

Actually, contrary to what was said in the other reply, there's a way to do this without a nuspec file.

Refer here: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#pack-target

NuGet has support for most nuspec elements through csproj as well.

So in your csproj, you would have something like:

<PackageTags>MyTag1;MyTag2</PackageTags>

0
votes

You can add a placeholder in the .nuspec file.

<tags>$tags$</tags>

and then set the property using the CLI.

C:> Nuget pack project.nuspec -Properties tags="MyTags"
0
votes

You should specify .nuspec file when adding a tag by nuget pack cli.

You can set metadata in .nuspec file. You can only modify it manually in .nuspec file to modify tags. Besides, you can also modify metadata in assemblies.cs file of your project, but it can’t modify tags.

Also you can find details about nuget pack -properties option:

Specifies a list of properties that override values in the project file; see Common MSBuild Project Properties for property names. The Properties argument here is 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. Note that for the "Configuration" property, the default is "Debug". To change to a Release configuration, use -Properties Configuration=Release.

So tags are not included in Properties argument, you can only modify $token$ in .nuspec file with -Properties arguments.