VS 2017 c# Getting Current Version number
-
The Properties > Publish page of my App shows a Publish Version of 5.0.0.7. When I use:-
Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
it always gives 1.0.0.0. How do I access the version number from the properties page?
-
The Properties > Publish page of my App shows a Publish Version of 5.0.0.7. When I use:-
Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
it always gives 1.0.0.0. How do I access the version number from the properties page?
These are the methods I use:
/// /// Gets the assembly Title /// public string AssemblyTitle { get { object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); if (attributes.Length > 0) { AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes\[0\]; if (titleAttribute.Title != "") { return titleAttribute.Title; } } return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); } } /// /// Gets the assembly Version /// public string AssemblyVersion { get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); } } /// /// Gets the assembly Description /// public string AssemblyDescription { get { object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyDescriptionAttribute)attributes\[0\]).Description; } } /// /// Gets the assembly Product /// public string AssemblyProduct { get { object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyProductAttribute)attributes\[0\]).Product; } } /// /// Gets the assembly copyright notice /// public string AssemblyCopyright { get { object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
-
These are the methods I use:
/// /// Gets the assembly Title /// public string AssemblyTitle { get { object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); if (attributes.Length > 0) { AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes\[0\]; if (titleAttribute.Title != "") { return titleAttribute.Title; } } return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); } } /// /// Gets the assembly Version /// public string AssemblyVersion { get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); } } /// /// Gets the assembly Description /// public string AssemblyDescription { get { object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyDescriptionAttribute)attributes\[0\]).Description; } } /// /// Gets the assembly Product /// public string AssemblyProduct { get { object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyProductAttribute)attributes\[0\]).Product; } } /// /// Gets the assembly copyright notice /// public string AssemblyCopyright { get { object\[\] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
-
AssemblyVersion still returns 1.0.0.0 despite the Properties > Publish page showing 5.0.0.7. That is with GetExecutingAssembly or with GetEntryAssembly. Am I missing something?
Probably, yes. From here though it's difficult to tell what. :laugh: Start by looking in the project Properties folder at the file AssemblyInfo.cs - copy and paste that so we can read it, along with the full path to the file - the version info is normally at the bottom. Then show exactly the code you used, what it displayed, and tell us the location of the file it's in (the full path helps here as well)
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Probably, yes. From here though it's difficult to tell what. :laugh: Start by looking in the project Properties folder at the file AssemblyInfo.cs - copy and paste that so we can read it, along with the full path to the file - the version info is normally at the bottom. Then show exactly the code you used, what it displayed, and tell us the location of the file it's in (the full path helps here as well)
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!