StefanKert / BuildVision

A Visual Studio extension to visualize the building process.
MIT License
261 stars 43 forks source link

Version Column #82

Open tb-mtg opened 5 years ago

tb-mtg commented 5 years ago

On the available columns to be displayed, could you introduce a "Version" column that shows the each project's version after the state changes to "BuildDone"?

This would help show any new version's that may have been automatically generated as part of the build.

StefanKert commented 5 years ago

Thanks for the idea. Can you give me additional details on what you mean with Version? Are you talking about the AssemblyVersion?

tb-mtg commented 5 years ago

According to this helpful page, .Net Core uses the project file (.csproj or .vbproj) the Version property (which is made up of VersionPrefix & VersionSuffix properties if Version is not specified) is used to determine the following properties:

So all of these properties could be used as optional columns if specified.

A fallback method could be using assembly attributes the reading the project files is not possible or any of the properties above are not specified.

[assembly: AssemblyVersion("1.2.3.4")]
[assembly: AssemblyFileVersion("6.6.6.6")]
[assembly: AssemblyInformationalVersion("So many numbers!")]
tb-mtg commented 5 years ago

Maybe something like below using an Xml reader may help:

using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
var projectPath = "c:\temp\Example.csproj";

var xmlProject = XDocument.Load(projectPath, LoadOptions.PreserveWhitespace);
var defaultNamespace = xmlProject.Root.GetDefaultNamespace();
var defaultNamespacePrefix = "ns";
var xmlNamespaceManager = new XmlNamespaceManager(new NameTable());
xmlNamespaceManager.AddNamespace(defaultNamespacePrefix, defaultNamespace.NamespaceName);

XElement GetPropertyGroupElement(string xElementName) {
  return xmlProject.Root.XPathSelectElement($"{defaultNamespacePrefix}:PropertyGroup/{defaultNamespacePrefix}:{xElementName}", xmlNamespaceManager);
}

var versionPrefix = GetPropertyGroupElement("VersionPrefix")?.Value;
var versionSuffix = GetPropertyGroupElement("VersionSuffix")?.Value;
var version = GetPropertyGroupElement(Program.Version)?.Value ?? versionPrefix + '-' + versionSuffix;

var assemblyVersion = GetPropertyGroupElement("AssemblyVersion")?.Value ?? versionPrefix;
var fileVersion = GetPropertyGroupElement("FileVersion")?.Value ?? assemblyVersion;
var informationalVersion = GetPropertyGroupElement("InformationalVersion")?.Value ?? version;
var packageVersion = GetPropertyGroupElement("PackageVersion")?.Value ?? version;