Accessing version info of another project

867 Views Asked by At

I have a VS solution with 2 Micro Framework C# projects A and B. I want B to access the AssemblyVersion of A (as specified in AssemblyInfo.cs). Is there a way to do that?

1

There are 1 best solutions below

1
Iñaki Elcoro On BEST ANSWER

You can't access AssemblyInfo as a class. AssemblyInfo only contains assembly level attributes, that can only be accessed via reflection.

You can use Assembly.Load("assemblypath") to load an assembly in memory and then access the version info via AsemblyName object:

var assembly = Assembly.Load(".\myassembly.dll");

AssemblyName nameInfo = assembly.GetName();

Console.Writeline(nameInfo.Version.ToString());

If your referenced assembly has been loaded first, you could also search it inside AppDomain loaded assemblies using AppDomain.Current.GetAssemblies