85

I want to append our application version with the build number. For example, 1.3.0.201606071.

When setting this in the AssemblyInfo, I get the following compilation error:

Error CS7034 The specified version string does not conform to the required format - major[.minor[.build[.revision]]]

Assembly info:

[assembly:System.Reflection.AssemblyFileVersionAttribute("1.0.0.201606071")]
[assembly:System.Reflection.AssemblyVersionAttribute("1.0.0.201606071")]
[assembly:System.Reflection.AssemblyInformationalVersionAttribute("1.0.0.201606071")]

Why would this be happening?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Dave New
  • 38,496
  • 59
  • 215
  • 394
  • 7
    Note: `AssemblyInformationalVersionAttribute` does not have restrictions as mentioned in the answers. – leppie Jun 21 '16 at 10:03
  • 4
    We ran into this same problem, and just ended up formatting our date like a version (ex. `2017.12.20.1234`, where 1234 is our build number) – neumann1990 Dec 20 '17 at 17:55

7 Answers7

91

The maximum value for either of the parts is 65534, as you read here. This is a limit imposed by the operating system, so not even specific to .NET. Windows puts the version numbers into two integers, which together form four unsigned shorts.

Adding some metadata to it (for the * option I guess) makes the maximum allowed value UInt16.MaxValue - 1 = 65534 (Thanks to Gary Walker for noticing):

All components of the version must be integers greater than or equal to 0. Metadata restricts the major, minor, build, and revision components for an assembly to a maximum value of UInt16.MaxValue - 1. If a component exceeds this value, a compilation error occurs.

Your 201606071 exceeds this limit.

Dan Atkinson
  • 11,391
  • 14
  • 81
  • 114
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • 9
    I'm experiencing this issue when trying to set a star value (`1.0.*`) in a .NET Core project with the new _csproj_ format file, having set `GenerateAssemblyInfo` to `false`. Any ideas? I'm looking to achieve auto increment in .NET Core / Standard projects of the new _csproj_ format file. – Shimmy Weitzhandler Oct 10 '17 at 09:01
  • 1
    No, I am sorry. Please ask a new question @Shimmy – Patrick Hofman Oct 10 '17 at 09:05
  • 3
    @Shimmy Did you end up asking that question? What did you find out? – jrh Dec 19 '17 at 15:42
  • 1
    We need a "Best of both worlds" solution for Assembly DATE AND Assembly Semantic Versioning. 1.yyyy.mmdd.buidNum – m1m1k Sep 30 '21 at 16:53
  • I was getting this error in Visual Studio 2022 in a .NET Standard 2.0 library and managed to figure out what I was doing wrong after re-reading the documentation and wanted to share what I did wrong in case others have the same issue. I had entered `1.0.*.*` with two wildcard asterisks. The solution was to change it to only one asterisk `1.0.*`. – Adam Shaver Aug 04 '22 at 01:41
31

If you are targeting netcoreapp2.0 and don't have AssemblyInfo.cs at all you can fix

error CS7034: The specified version string does not conform to the required format

by adding this into your .csproj file:

<PropertyGroup>
  <GenerateAssemblyInfo>False</GenerateAssemblyInfo>
  <Deterministic>False</Deterministic>
</PropertyGroup>
Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121
15

It's because each number in the version is a ushort! That's a pity.

Dave New
  • 38,496
  • 59
  • 215
  • 394
  • 2
    Actually its 65534 not 65535. – Gary Walker Jun 21 '16 at 10:04
  • 8
    @PatrickHofman - Yes, a ushort is limited to 65535, but the [build number is limited to 65534](https://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx) – Gary Walker Jun 21 '16 at 10:09
  • Oddly, each field in AssemblyVersion is limited to 65534, but in AssemblyFileVersion the limit it 65535. Yeah for consistency! – Jesse Chisholm Jan 19 '22 at 00:12
  • One also has to wonder why there is `Version.MajorRevision` and `Version.MinorRevision` (the high and low 16 bits respectively) if the `Revision` field is only 16-bits total. – Jesse Chisholm Jan 19 '22 at 00:13
5

In the .csproj file you must set Deterministic to false. Then accepts the compiler a '*' in the Build or Revision.

HRolle
  • 51
  • 1
  • 1
4

Yes you can do it (both in .NET Framework and in .NET Core) for the AssemblyFileVersion and AssemblyInformationalVersion, just not for the AssemblyVersionAttribute.

  • The AssemblyVersionAttribute is the only one that's actually limited to 4 ushort values - if you specify anything more the compiler will complain with error CS7034: The specified version string does not conform to the required format - major[.minor[.build[.revision]]], and there is nothing you can do about it.
  • The AssemblyFileVersionAttribute can be used with larger values, e.g. to encode date values with (for example in the Patch part of a semver), but will generate warning CS7035: The specified version string does not conform to the recommended format - major.minor.build.revision. Luckily, because it's a warning, it can be suppressed (see below).
  • The AssemblyInformationalVersionAttribute isn't constrained to anything and can contain a prerelease semver like "1.2.6-CI20220906", or any other random string really.

That is, the following will work:

#pragma warning disable CS7035 // The specified version string does not conform to the recommended format - major.minor.build.revision 

[assembly: AssemblyVersionAttribute("1.4.0.0")]
[assembly: AssemblyFileVersionAttribute("1.4.220831.0")]
[assembly: AssemblyInformationalVersionAttribute("1.4.220831-prerelease+build")]

#pragma warning restore CS7035

For .NET Core, you can either:

  • Disable auto-generated assembly attributes and include these attributes in your own AssemblyInfo.cs
  • Keep the version in the csproj file. In that case, in "Project properties", under "Build", "Suppress specific warnings", include "7035" in the list of warnings to suppress.
Leon Bouquiet
  • 4,159
  • 3
  • 25
  • 36
1

This limitation only applies to the Assembly and File version so if you are using .Net Core 2.x you can get around this limitation by settings a separate version of each in the csproj.

</PropertyGroup>
    <VersionPrefix>1.1.1.9000001</VersionPrefix>
    <VersionSuffix>$(VersionSuffix)</VersionSuffix>
    <AssemblyVersion>1.1.1.0</AssemblyVersion>
    <FileVersion>1.1.1.0</FileVersion>
</PropertyGroup>
J.D. Cain
  • 639
  • 4
  • 16
0

In some cases maybe Treat warnings as errors is enabled in project properties and versions like 1.3.0-4011 will cause following error:

Properties\AssemblyInfo.cs(35,32): error CS7035: The specified version string does not conform to the recommended format - major.minor.build.revision

So you can Change it using Visual Studio by selecting None or by setting TreatWarningsAsErrors to false in .csproj file.

Treat warnings as errors in project properties

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>none</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>..\..\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
  </PropertyGroup>
Ziaa
  • 128
  • 4