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

The GetAssemblyIdentity task returns me only AssemblyVersion, not AssemblyInformationalVersion.

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

+5
source share
1 answer

If you want to read the value of AssemblyInformationVersion from the actual binary assembly file, your question, how it is currently written, suggests that it is (alluding to GetAssemblyIdentity -task).

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

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

If you need to analyze the source code (for example, AssemblyInfo.cs ) for its value (this is a completely different thing!), And the Regex approach to which you are attached is not universal enough for your purposes, you will have to resort to using Roslyn or whatever or any other technology that really understands C # and can correctly analyze the source code.

+1
source

Source: https://habr.com/ru/post/1270009/


All Articles