Jerther
Jerther

Reputation: 5986

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

In AssemblyInfo.cs:

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

Will generates a 1.0.x.x 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?

Upvotes: 4

Views: 6220

Answers (2)

illegal-immigrant
illegal-immigrant

Reputation: 8224

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.

P.S 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.x.x 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

Upvotes: 1

H&#229;kan Fahlstedt
H&#229;kan Fahlstedt

Reputation: 2095

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, i.e "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.

Upvotes: 3

Related Questions