Backstory: We have a terminal app that uses WCF services and an MVC web back-end. We want to show the version # of the terminal on the MVC page.
To do this, first create a SharedAssemblyInfo.cs in a solution folder, or in your main project file. It will contain no more than the following text:
// Solution version
using System.Reflection;
[assembly: AssemblyVersion(“0.1.1.6”)]
[assembly: AssemblyFileVersion(“0.1.1.6”)]
For each project that will be sharing this file,
(a) go to the /Properties/AssemblyInfo.cs file and comment out the version # stuff.
(b) Add an existing file to the project. Find the SharedAssemblyInfo.cs and click the dropdown next to “Add” and select “Add as link”.
Done!
If you are displaying a version number in your web project and System.Reflection.Assembly.GetExecutingAssembly() returns null, you need to use GetEntryAssembly().
If you find that the version # always returns 0.0.0.0 when using (System.Reflection.Assembly.GetexecutingAssembly() ?? System.Reflection.Assembly.GetEntryAssembly()).GetName().Version.ToString(), then get a type that is outside your Assembly (I have a Common project consumed by all assemblies) and get its version # from that, like this:
typeof(Some.Type.Outside.of.Web.Assembly).Assembly.GetName().Version.ToString()
Hope this helps!