Recently working on a ASPCore Web Api (C#) I wanted to add a version endpoint so I can tell which version of a given API Im working with. Its a public API so I don't want to include things that might be used to determine vulnerabilities such as third party package version etc. So far I've got the Following.
// GET api/values
[HttpGet]
public string Get()
{
var attributes = Assembly.GetEntryAssembly().CustomAttributes;
string versionInfo=null;
foreach(var attribute in attributes)
{
if (attribute.AttributeType.Name.StartsWith("Assembly")&& attribute.AttributeType.Name.EndsWith("Attribute"))
{
string name = attribute.AttributeType.Name;
name = name.Substring(8, name.Length - 17);
versionInfo = string.Concat(versionInfo, name, ":");
versionInfo = string.Concat(versionInfo, attribute.ConstructorArguments.FirstOrDefault());
versionInfo = string.Concat(versionInfo, System.Environment.NewLine);
}
}
return versionInfo;
}
which Produces
Company:"Company Name"
Configuration:"Debug"
Description:"Package Description"
FileVersion:"0.0.1.0"
InformationalVersion:"0.0.1"
Product:"ProductName"
Title:"PackageTitle"
Is there any more industry standard approach to this. Seems it would be a fairly standard issue but Im not seeing any sort of standard way to accomplish this from my brief date with Google.