I have a function, which returns the Assembly File Version of a C# project (in Visual Studio). The problem is, that it is not located in the main project, so instead of returning the version of the actual application, it returns the version of the project (assembly) that it is located in. I have tried using GetCallingAssembly()
to get the version of the primary project instead, but without luck. And even if I got it to work, I could image that it breaks quite easily, if I chain my calls through multiple project. Is there a way to get the version of a project, by its name? For instance, if my main project is called SolutionName.ProjectName, and the primary window (it's a WPF project) is called MainWindow.xaml (if that makes any difference).
My current code:
private string GetFileVersion()
{
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetCallingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
return fvi.FileVersion;
}