Solved

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

Posted on 2016-09-09
9
48 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 63

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 63

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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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
 
LVL 63

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 63

Expert Comment

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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