Reputation: 11
I am working on a .net project and I am not able to understand how to access the assembly version from the AssemblyVersion.cs file that is being generated by the GitVersion.MSBuild task.
I would like to include the commit hash in the version of my application and print that in the footer of my website, but the documentation just says to include the GitVersion.MSBuild and the rest is done. All examples are either for f# or projects that contain a csproj file or some kind of build script.
This project does not have any of that. It's just a bunch of .aspx files with .cs as the code behind and there is little compiling done during the build or deployment (or at least it seems that way).
From my .cs file where I want to display this data, I'm hoping to access it somehow like the following:
String websiteVersion = AssemblyInfo.GetType("GitVersionInformation");
I'm having trouble understanding how I can access any of the properties of the file if it's being generated at compile time.
Upvotes: 0
Views: 598
Reputation: 1260
var assembly = Assembly.GetExecutingAssembly();
var versionAttribute = (AssemblyInformationalVersionAttribute)assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)[0];
var version = versionAttribute.InformationalVersion;
This will return GitVersion-generated version as string
Upvotes: 0