Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is correct way to get AssemblyInformationalVersion from assembly in MSBuild?

Tags:

c#

msbuild

GetAssemblyIdentity task seems to return me only AssemblyVersion, not AssemblyInformationalVersion.

I can parse AssemblyInfo.cs, as suggested by here Reading AssemblyInformationalVersion value from AssemblyInfo file with RegEx but I don't think this is optimal solution.

like image 686
Leotsarev Avatar asked Nov 07 '22 19:11

Leotsarev


1 Answers

If you want to read the AssemblyInformationVersion value from the actual assembly binary, your question, as it is currently written, suggests this is the case (hinting at the GetAssemblyIdentity-task).

If so, just use FileVersionInfo.GetVersionInfo and read the ProductVersion property. To invoke this from inside MSBuild you probably need a small custom task, that does that.

Internally, that is what the C# compiler turns the AssemblyInformationalVersion into.

If, you need to parse the source code (e.g. of AssemblyInfo.cs) for its value (which is a totally different thing!) and the Regex-approach you linked to is not versatile enough for your purposes, you'll have to resort to using Roslyn, or some other technology that actually understands C# and can properly parse the source code.

like image 53
Christian.K Avatar answered Nov 14 '22 23:11

Christian.K