NuSpec - how to trim $version$ down to Major.Minor.Build (SemVersion)?

拟墨画扇 提交于 2019-12-13 04:22:00

问题


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.


回答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:

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.



来源:https://stackoverflow.com/questions/49151226/nuspec-how-to-trim-version-down-to-major-minor-build-semversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!