99

I can't use * in assembly version; when I do I get the following compilation error:

The specified version string contains wildcards, which are not compatible with determinism. Either remove wildcards from the version string, or disable determinism for this compilation

SCRAssembly

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Lucyper
  • 1,049
  • 1
  • 8
  • 10
  • 3
    Specific to .NETCore projects, /deterministic compile option. You'd have to edit the .csproj file by hand to turn it off. Do beware that the version is considerably worse that non-deterministic, as written the revision number will be the time of day. So version numbers can go backwards or repeat, you might as well not use them at all. – Hans Passant Dec 14 '18 at 15:11
  • 9
    Always post error message (and code) as text, not as images. – H H Dec 14 '18 at 15:28

4 Answers4

104

Add <Deterministic> tag with false value and use * for the 3'rd part of AssemblyVersion inside <PropertyGroup> in .csproj file:

<PropertyGroup>
    <ProduceReferenceAssembly>true</ProduceReferenceAssembly>
    <Version>1.0.0</Version>
    <AssemblyVersion>1.0.*</AssemblyVersion>
    <Deterministic>false</Deterministic>
</PropertyGroup>

"Deterministic" means something like - the compiler will use the same versions of the files if no changes have happened resulting in faster builds.

It is the AssemblyVersion (not AssemblyFileVersion) that you should use a wildcard in. If you provide AssemblyVersion with wildcard, just don't include AssemblyFileVersion at all.


Note also: There are two forms. One where the asterisk wildcard is in the third position (x.y.*) and one where it is in the fourth position (x.y.z.*).

x.y.* auto-generates the BUILD and REVISION numbers. BUILD is the "number of days since 1st January 2000" thus it only changes once each day. and REVISION is "half the number of seconds since 00:00".

Today, for example, an AssemblyVersion of '1.0.*' will generate a specific '7472', e.g. '1.0.7472.20737'. The 5-digit final number will be different every build, at least if changes.

This may be better than 1.0.0.* for support as it indicates age (.7300 would be almost 6 months old). The example, 1.0.7472.20737, means "this assembly was built on 2020-06-16 at 11:31:14".

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
John Deer
  • 2,033
  • 2
  • 13
  • 16
  • That doesn't seem to work for VS Pro 2019. Just creates a ref folder with a bad exe in it. – Chizl May 20 '22 at 02:08
77

I guess you were able to use it earlier and can't anymore.

Reason - There have been some changes to Visual Studio as the new project files now default to 'True' for 'Deterministic' attribute.

Solution - as Hans Passant says, edit project file by hand. Cons to doing it, also as he says.

Specifically, edit .csproj to <Deterministic>false</Deterministic>.

Source - https://marinovdh.wordpress.com/2018/10/22/68/

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Animesh
  • 1,166
  • 1
  • 13
  • 12
  • This does not resolve the issue on my VS2022 (17.6.2). Still getting that error stating that the specified version does not conform to the recommended format. – benzhi Jun 07 '23 at 07:57
4

VS2019 can auto-create an .editorconfig file putting severity as 'suggest', which content is like this:

[*.cs]

    # CS7035: The specified version string does not conform to the recommended format - major.minor.build.revision
    dotnet_diagnostic.CS7035.severity = suggestion

enter image description here

John Deer
  • 2,033
  • 2
  • 13
  • 16
1

I found this cool workaround for .Net Core projects that sheds lights on @Hans comment.

<PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <VersionSuffix>1.$([System.DateTime]::UtcNow.ToString(yyMM)).$([System.DateTime]::UtcNow.ToString(ddhh)).$([System.DateTime]::UtcNow.ToString(mmss))</VersionSuffix>
        <AssemblyVersion Condition=" '$(VersionSuffix)' == '' ">1.0.0.1</AssemblyVersion>
        <AssemblyVersion Condition=" '$(VersionSuffix)' != '' ">$(VersionSuffix)</AssemblyVersion>
        <Version Condition=" '$(VersionSuffix)' == '' ">1.0.0.1</Version>
        <Version Condition=" '$(VersionSuffix)' != '' ">$(VersionSuffix)</Version>
        <!--Deterministic tells the compiler to use the same versions of the files if no changes have happened resulting in faster builds-->
        <Deterministic>false</Deterministic>

REF: https://sachabarbs.wordpress.com/2020/02/23/net-core-standard-auto-incrementing-versioning/

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321