6

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.

Leotsarev
  • 1,040
  • 7
  • 23
  • Correct? Depends on your usecase. Your question says reading from assembly, the link you provides read it from AssemblyInfo.cs. What is your intention? – Frode Nilsen Jul 20 '17 at 10:39
  • My intention is to read from Assembly. I don't think that parsing something with RegExp is optimal solution – Leotsarev Jul 20 '17 at 11:58
  • Just to be clear: you want to read the AssemblyInformationalVersion from the binary assembly file or from the AssemblyInfo.cs source file? Your question indicates both could be the case. – Christian.K Jul 20 '17 at 12:16

1 Answers1

1

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.

Christian.K
  • 47,778
  • 10
  • 99
  • 143