Solved

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

Posted on 2016-09-09
9
46 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

MS Dynamics Made Instantly Simpler

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net, radiobuttonlist, c# 3 69
I need help writing Unit Tests for my ASP.Net MVC application 5 40
c#  FTP ftpwebrequest URI invalid 6 47
What!!!??? 5 60
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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