简体   繁体   中英

C# AssemblyVersion 3 digits for use with NuGet's PreRelease versioning

In AssemblyInfo.cs :

[assembly: AssemblyVersion("1.0.*")]

Will generates a 1.0.xx four digits version number.

Which, if I use this nuspec metadata:

<version>$version$-test</version>

generates an error when packing:

The version « 1.0.5431.31092-test » does not follow semantic version control instructions

Is there a simple way around this?

Not possible, an assembly's version is stored in the System.Version class, that consists of Major, Minor, Build and Revision.

EDIT: I was a bit to hasty to answer. When you use the AssemblyVersionAttribute's constructor with a string containing an asterix, all four properties of a version will be generated. The only way to cause a version with lesser numbers is to specify the exact version number, without asterix, ie "1.0.1". See: http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.assemblyversionattribute(v=vs.110).aspx

What you could do, if you want lesser numbers in the version and also generated version numbers, is to use an external tool altering version numbers in the pre-build step.

No post processing is necessary, NuGet is using [assembly: AssemblyInformationalVersion("")] as a package version, set it to whatever number of componets you please and be done with it.

PS I strongly encourage you to also set AssemblyVersion as this is the one .NET actually uses, at least set it to auto increment

Some reading available here

Full example

[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyInformationalVersion("1.0")]

Will generate a package Lib.1.0.nupkg containing assembly with 1.0.xx version, version you will be dealing with is 1.0

Whenever you want to change nuget version, just change AssemblyInformationalVersion , not touch AssemblyVersion at all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM