question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How to version dotnet core assemblies

See original GitHub issue

@golfguy0082 commented on Thu Apr 06 2017

Forgive me if this is not the appropriate channel for a question. I’m trying to figure out how to version (and retrieve) assembly versions in dotnet core (both build and publish). I’ve been searching for documentation on this, but I’ve come up empty. Below are some things I’ve tried.

dotnet publish /p:Version=3.0.1 (where [Version]3.0.0[/Version] is defined in csproj) dotnet publish --version-suffix 1 (where [VersionPrefix]3.0[/VersionPrefix] is defined in csproj)

I’m retrieving the version using the following code: typeof(ReflectionUtils).GetTypeInfo().Assembly.GetName().Version.ToString(); ReflectionUtils is an arbitrary type in my assembly. No matter what I try, the version retrieved from the above line shows 3.0.0.0.

Can anyone point out what I’m doing wrong, or point me in the direction of a page that explains some of this stuff more fully?


@karelz commented on Thu Apr 06 2017

The code you wrote inspects assembly version (defined by AssemblyVersionAttribute).

I don’t know what the dotnet publish command sets in csproj – @davkean any idea where to direct the question? Does it belong into your area or CLI area?


@tarekgh commented on Fri Apr 07 2017

CC @weshaggard @ericstj

@golfguy0082 net core is not different than the full framework. you can set the assembly version in your assembly by adding the attributes like

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

and the way you are calling Assembly class to get the version is correct. The example in the link https://msdn.microsoft.com/en-us/library/system.reflection.assembly(v=vs.110).aspx is demonstrating that


@weshaggard commented on Fri Apr 07 2017

.NET Core tooling is a little different because we have enabled folks to set the value in msbuild properties directly. @golfguy0082 have a look at https://github.com/dotnet/sdk/issues/2 which is I think the closest set of documentation that I can find on the matter.


@tarekgh commented on Fri Apr 07 2017

I’ll move this issue to the SDK repo per Wes comment

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
weitzhandlercommented, Oct 10, 2017

How can I achieve auto increment of the assembly version like we could with AssemblyVersion("1.0.*") (which generates this compiler error in the new projects):

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

Any ideas please?

5reactions
svickcommented, Oct 11, 2017

@weitzhandler Looking at the source code, wildcards are only allowed if the build is not deterministic, which seems to be the default for .Net Core projects.

Adding <Deterministic>False</Deterministic> to my csproj indeed fixes the issue for me.

Though the error message does not help with figuring that out, so I have opened an issue about that: https://github.com/dotnet/roslyn/issues/22660.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Versioning in .NET core
To get the .Net Core version our application is targeting, we use the System.Reflection namespace again to get the entry assembly information.
Read more >
Classic or Custom Build and Version Numbers for ...
Classic/custom build for assembly version for .NET 5 and 6. In this tip, you will learn how to create a custom build and...
Read more >
Assembly versioning
Learn about versioning of .NET assemblies. All versioning of assemblies that use the CLR is done at the assembly level.
Read more >
Assembly Versioning and DLL Hell in C# .NET Framework
Is there a way to load multiple versions of an assembly side by side in .net core? ? Anonymous. -1 ...
Read more >
How to Assembly versioning
The AssemblyVersion attribute is used to assign a specific version number to the assembly, which is then embedded in the assembly's manifest. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found