I have modified my assemblyinfo.cs with this:
[assembly: AssemblyVersion("1.0.*")]
and on the _layout.cshtml I put this so I can recognize in which build I am testing:
@System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
it always prints 0.0.0.0
When I go to the bin folder and check the dll properties, version says 1.0.343.2323 so I dont get it?
In C#, GetExecutingAssembly() method is the method of Assembly class. This method returns the assembly that contains the code that is currently executing. To use this method we have to use System. Reflection in our program.
Namespace: System.Reflection. Summary. Defines an Assembly, which is a reusable, versionable, and self-describing building block of a common language runtime application.
The recommended way to retrieve an Assembly object that represents the current assembly is to use the Type. Assembly property of a type found in the assembly, as the following example illustrates. To get the assembly that contains the method that called the currently executing code, use GetCallingAssembly.
Loads an assembly given its AssemblyName. The assembly is loaded into the domain of the caller using the supplied evidence. Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly. The assembly is loaded into the application domain of the caller.
Assembly name shown is of some runtime assembly loaded by IIS
, instead use EntryAssembly
if entry point for your application resides in the assembly for which you have updated the AssemblyInfo -
Assembly.GetEntryAssembly().GetName().Version.ToString();
In case it's different than the calling assembly you can do this way -
Assembly.GetAssembly(typeof(YourAssembly.AnyClass)).GetName().Version.ToString();
Looks like the executing assembly is not the one you've compiled, but a dynamic assembly created by IIS.
Try using
typeof(Your_Type_From_NonWeb_Assembly).Assembly.GetName().Version.ToString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With