BendEg BendEg - 10 days ago 6
C# Question

Generating nuget package using .csproj cause wrong version number

Currently I'm creating a nuget package using a *.csproj and a nuspec file. In the nuspec file I'm declaring the assembly/package version like this:

<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
...
</metadata>
</package >


In the assembly the version is declared like this:

[assembly: AssemblyVersion("6.0.0")]
[assembly: AssemblyFileVersion("6.0.0")]


The problem is, that when I create the package using
nuget pack xxx.csproj
,
it creates a package with the version
6.0.0.0
instead of
6.0.0
. This makes a problem when installing the assembly using nuget, because visual studio is searching in
package/.../6.0.0
for the assembly, but it is stored in
packages/.../6.0.0
.

Is this a known issue?

Answer

NuGet uses other attribute to generate the version replaced in $version$:

[assembly: AssemblyInformationalVersion("6.0.0")]

As said in how to version assemblies destined for Nuget NuGet uses this attribute because nothing else seems to care about it :) the AssemblyInformationalVersion attribute is a literal one that can be used for semantic versions