Skip to content

Instantly share code, notes, and snippets.

@dsoprea
Last active October 17, 2016 17:31
Show Gist options
  • Save dsoprea/8199fb00dc2b3bdd060a876331ac2679 to your computer and use it in GitHub Desktop.
Save dsoprea/8199fb00dc2b3bdd060a876331ac2679 to your computer and use it in GitHub Desktop.
C# code for the properties that can retrieve the version embedded in the executable: http://wp.me/p3Uuaw-Hj
class Program
{
private string executableVersion = null;
private string ExecutableVersion
{
get
{
if (executableVersion == null)
{
Assembly assembly = Assembly.GetExecutingAssembly();
string assemblyName = assembly.GetName().Name;
// "Properties" is required since it is located in the
// Properties folder of the project and was thusly embedded
// as such.
string filepath = assemblyName + @".Properties.executable.version";
string[] names = assembly.GetManifestResourceNames();
var stream = assembly.GetManifestResourceStream(filepath);
if (stream == null)
{
throw new Exception(String.Format("Could not get resource-stream with name [{0}] for version content from assembly [{1}]. Available: {2}", filepath, assembly.FullName, String.Join(",", names)));
}
TextReader tr = new StreamReader(stream);
executableVersion = tr.ReadToEnd().Trim();
}
return executableVersion;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment