4

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?

Jerther
  • 5,558
  • 8
  • 40
  • 59
  • 1
    What do you mean "three digits one"? Clearly `Assembly.GetName().Version` has 4 parts (due to being `System.Version`)... so you probably mean something different, but unclear what. – Alexei Levenkov Nov 14 '14 at 22:06
  • Ok I get this now. The class has a three digits constructor but its properties are not nullable. That makes sens. – Jerther Nov 14 '14 at 22:13

2 Answers2

3

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.

Håkan Fahlstedt
  • 2,040
  • 13
  • 17
  • the class has a three digits constructor, and the ToString() method even returns a three digits version: http://msdn.microsoft.com/en-us/library/00dkw4kk(v=vs.110).aspx – Jerther Nov 14 '14 at 22:09
  • You're correct, I was mixing up System.Version and the behaviour of AssemblyVersionAttribute. If you use "1.0.x" in AssemblyVersionAttribute's constructor, both Build and Revision will be generated. I've edited my answer. – Håkan Fahlstedt Nov 14 '14 at 22:15
  • Still, your answer helped me understand. It's an object not a string – Jerther Nov 14 '14 at 22:19
  • 1
    Even if I set "1.0.1", NuGet sees "1.0.1.0" which makes sens since Version is an object with non nullable int members, so "1.0.1.0-test" still generate an error beacue of the extra digit. – Jerther Nov 14 '14 at 22:47
  • 1
    @Jerther Why did you mark this as an answer to your question? It does not solve the problem at all, and is in fact incorrect: nuget will still get 4 digits even if a 3 digit version is specified in the `AssemblyVersion`. I created a [new question about the number of digits issue](http://stackoverflow.com/questions/28194498/nuget-pack-does-not-honor-number-of-digits-on-assembly-version) which I feel is the core problem that would also solve your issue here if fixed. – julealgon Jan 28 '15 at 14:21
  • 1
    `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.` This would not help at all. Even if the attribute has only 3 explicit digits, the nuget parsing process seem to always use all 4 digits. – julealgon Jan 28 '15 at 14:23
  • An external tool works. I made one that reads the assembly version which always has four digits and only take the first three and put it in the nuspec. – Jerther Jan 28 '15 at 14:51
1

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

illegal-immigrant
  • 8,089
  • 9
  • 51
  • 84