2

I have a C# solution, let's say MySolution and inside this I have 2 projects, let's say ProjectA and ProjectB. ProjectA is used as a reference for ProjectB.

How can I obtain the version of ProjectB inside the classes from ProjectA ?

I can obtain the version of ProjectB inside the code of ProjectB by using the following syntax :

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version

Marlon
  • 19,924
  • 12
  • 70
  • 101
Simon
  • 4,999
  • 21
  • 69
  • 97
  • You mean the other way around? otherwise you will get circular dependency – MBen Jun 20 '12 at 08:05
  • [I know it is too late for the answer but it's really works](https://stackoverflow.com/questions/10498209/reading-the-version-number-from-a-assemblyinfo-cs-file) – Mhd Feb 07 '18 at 14:03

1 Answers1

8
Type.GetType(assemblyQualifiedNameFromProjectB).Assembly.GetName().Version

Or with any other instance (via instance.GetType().Assembly) or type of someting coming from ProjectB. You can also load the assembly explicitly and then get the version of that.

Lucero
  • 59,176
  • 9
  • 122
  • 152
  • ProjectB depends on ProjectA, won't this code create ciruclar dependency? – MBen Jun 20 '12 at 08:09
  • 1
    You cannot add it as project reference (because these dependencies are resolved at load time where circular references are not allowed), but once both assemblies are loaded their types and instanes can be passed around and queried freely. Therefore this works fine. – Lucero Jun 20 '12 at 08:11