Last active
October 17, 2016 17:31
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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