30

In the old .NET framework, you could set the [assembly: AssemblyVersion("1.0.*")] and the compiler would auto-increment the version.

With .NET core, I've tried all sorts of things, but I can't get it to auto-increment.

  • I've added <Deterministic>False</Deterministic> and <AssemblyVersion>1.0.*</AssemblyVersion> to the .csproj per similar question. The code compiles but the version stays the same
  • I've tried the same thing but with <Version>1.0.*</Version> tag as described here. This actually set the product version to 1.0.* (with the asterisk).
  • I've set the Assembly Version in the Property Properties/Package page. Doesn't seem to do anything either.

None of it seems to work. Am I missing something simple? This is just a standard .NET Core Web Project.

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
  • when we say auto increment version is each time you build a release on your local environment? what is your definition of auto increment? hence the way I would do it is when I build using Jenkins or Azure Devops, it is set in devops tools to auto increment after each build. – Maytham Fahmi Aug 10 '20 at 04:09
  • @maytham-ɯɐɥʇʎɐɯ To start with, I'd like to figure how to auto-increment on my local environment. – AngryHacker Aug 10 '20 at 04:13
  • 1
    One simple way I did it previously is reading the current version and increase it by one, so to get version and increment by command line. That said I found this articale not sure if it anser your question, let me know https://sachabarbs.wordpress.com/2020/02/23/net-core-standard-auto-incrementing-versioning/ – Maytham Fahmi Aug 10 '20 at 04:22
  • @maytham-ɯɐɥʇʎɐɯ That actually worked. Thank you. I am honestly surprised that this functionality isn't baked into the framework. – AngryHacker Aug 10 '20 at 05:29
  • I am happy os to hear, I left it as answer so other can get benefit of it. – Maytham Fahmi Aug 10 '20 at 05:33

1 Answers1

15

One simple way I did it previously is by reading the current version and increasing it by one, so you get the current version and increment by one using the command line.

With that said, it is possible to do the following for the .net core project:

In your .csproj file, you add the following:

<PropertyGroup>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <Deterministic>false</Deterministic>
</PropertyGroup>

In your code, for instance, in your entry point class, add the following:

using System.Reflection;

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

When you build the code, it will get a version like 1.0.8419.40347.

enter image description here

To make more customization, check this article: https://sachabarbs.wordpress.com/2020/02/23/net-core-standard-auto-incrementing-versioning/

In addition, I added this link:

Equivalent to AssemblyInfo in dotnet core/csproj

And I use this exertion as well for Visual Studio:

https://marketplace.visualstudio.com/items?itemName=PrecisionInfinity.AutomaticVersions

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
  • 1
    It seems that secrets don't work in Development with this configuration – steakoverflow Feb 04 '23 at 16:37
  • Maybe i did get it. But what does secret has to do with version – Maytham Fahmi Feb 04 '23 at 17:06
  • 1
    If your application uses secrets, switching the deterministic option to false will break the functionality that reads the secrets at runtime. You would not think that the two are related, but unfortunately, they are. – Alek Davis May 02 '23 at 17:57