I'm creating a .NuSpec file with
<metadata>
<version>$version$</version>
<!-- ... -->
</metadata>
Unfortunately, that returns the assembly's version in Major.Minor.Build.Revision format. I need to trim this down to 3 parts only (Major.Minor.Build) for compatibility with SemVersion as used by Squirrel.
Is there any way to do this? I'd prefer not having to put in the version number by hand for each release.
Is there any way to do this? I'd prefer not having to put in the version number by hand for each release
If you do not want to modify the version number by hand for each release, you probably don't need .nuspec
. You can run nuget pack
with the project file directly:
nuget pack MyProject.csproj
According to the Replacement tokens, when we pack the .csproj
directly, the value source of $version$
comes from file AssemblyInfo.cs
or AssemblyInfo.vb
:
So nuget will use the value of AssemblyInformationalVersion
if present, otherwise AssemblyVersion. It is removed by default, because they don’t apply to semantic versioning. when we add it to the AssemblyInfo.cs
file:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0")]
Nuget will actually apply whatever is in that string as the package version.
Notice that the informational version only contains three numbers. So it compatibility with SemVersion as used by Squirrel.
Source:How to Version Assemblies Destined for Nuget
Hope this helps.