Solved

Could you point how to obtain the assembly version and  other assembly data from a project programatically?

Posted on 2016-09-09
9
41 Views
Last Modified: 2016-09-09
Hi Experts

Could you point how to obtain the assembly version and  other assembly data from a project programatically?

img001
Thanks in advance.
img_ee_001_090916.png
0
Comment
Question by:Eduardo Fuerte
  • 4
  • 4
9 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 41791644
You could use the AssemblyInfo Class to get that information.
// Add a reference to Microsoft.VisualBasic.dll
// Add this using statement
using Microsoft.VisualBasic.ApplicationServices;

// Get the AssemblyInfo for the main assembly
var assemInfo = new AssemblyInfo(System.Reflection.Assembly.GetEntryAssembly());
// Access the information
Console.WriteLine (assemInfo.Version  );
Console.WriteLine ( assemInfo.CompanyName );

Open in new window

0
 

Author Comment

by:Eduardo Fuerte
ID: 41791743
Hi Fernando

I'm using C#.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41791767
Yes I know. In your project make a reference to the Microsoft.VisualBasic.dll then add a using statement using Microsoft.VisualBasic.ApplicationServices; which will allow you to use the Visual Basic methods in your C# applications. Then try running the code I posted.
0
 

Author Comment

by:Eduardo Fuerte
ID: 41791792
Unfortunatelly since I got this error when tryed:
img003
But this code runs
img002
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
                string version = fvi.FileVersion;

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41791821
No not a NuGet package. To add a reference to a dll open Solution Explorer right click on the References node and then in the menu that pops up click on Add Reference..., when the Reference Manager window opens type Microsoft.VisualBasic in the search box as shown below. Make sure that you click on the dll Name so that it has a check mark to the left and then click OK button. Adding a reference to a project
0
 

Author Closing Comment

by:Eduardo Fuerte
ID: 41791840
Perfect, Fernando!

Sorry my confusion,

Thank you very much!
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41791846
Not a problem Eduardo, glad to help.
0
 
LVL 33

Expert Comment

by:it_saige
ID: 41791860
*NO POINTS*

There is no big secret, these are stored as a part of the metadata for the application as attributes.  As Fernando has stated, you can use the AssemblyInformation class provided in the Microsoft.VisualBasic.dll or you can use the Assembly class in System.Reflection.

To get the information you requested we would do the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace EE_Q28968811
{
	class Program
	{
		static void Main(string[] args)
		{
			foreach (var pair in Assembly.GetEntryAssembly().EntryAssemblyMetaData())
				foreach (var value in pair.Value)
					Console.WriteLine("{0}: {1}", pair.Key, value);
			Console.ReadLine();
		}
	}

	static class Extensions
	{
		public static Dictionary<string, List<string>> EntryAssemblyMetaData(this Assembly assembly)
		{
			return (from attribute in assembly.GetCustomAttributes(false).Cast<Attribute>()
				   from property in attribute.GetType().GetProperties()
				   where !property.Name.Equals("TypeId", StringComparison.OrdinalIgnoreCase)
				   group property.GetValue(attribute, null).ToString() by attribute.GetType().Name into properties
				   select new { properties.Key, properties }).ToDictionary(x => x.Key, y => y.properties.ToList());
		}
	}
}

Open in new window

Which produces the following output -Capture.JPG
-saige-
0
 

Author Comment

by:Eduardo Fuerte
ID: 41791888
Thank you for the reply, it_saige.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now