0

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.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
Bogey
  • 4,926
  • 4
  • 32
  • 57
  • Possible duplicate of [nuspec and csproj package version tags](https://stackoverflow.com/q/48676663) – NightOwl888 Mar 07 '18 at 11:53
  • Thanks, interesting - but, I'm not using the new csproj format, so unfortunately that would not apply to me by looks – Bogey Mar 07 '18 at 12:02

1 Answers1

1

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 .csprojdirectly, the value source of $version$ comes from file AssemblyInfo.cs or AssemblyInfo.vb:

enter image description here

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.

enter image description here

Source:How to Version Assemblies Destined for Nuget

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thanks Leo, that input is very helpful! I tried having the version auto-increment (e.g. specified AssemblyVersion as "1.0.*"), which ended up resulting in 4-piece version strings. I'll try to apply this to AssemblyInformationalVersion! – Bogey Mar 08 '18 at 10:05