[英]How to find out the ProductName property of another assembly?
I have two assemblies A.exe and B.exe. 我有两个程序集A.exe和B.exe。 Both are Windows.Forms .net 3.5 assemblies. 两者都是Windows.Forms .net 3.5程序集。 A.exe knows that B.exe is in the same directory. A.exe知道B.exe在同一目录中。
How can I find out the ProductName of B.exe from A.exe? 如何从A.exe找出B.exe的产品名称 ?
The FileVersionInfo class is useful here. FileVersionInfo类在这里很有用。 The [AssemblyProduct] attribute gets compiled into the unmanaged version info resource. [AssemblyProduct]属性被编译到非托管版本信息资源中。 This code works on any .exe: 此代码适用于任何.exe:
private void button1_Click(object sender, EventArgs e) {
var info = System.Diagnostics.FileVersionInfo.GetVersionInfo(@"c:\windows\notepad.exe");
MessageBox.Show(info.ProductName);
}
The following is an example on how to read assembly information through code. 以下是有关如何通过代码读取程序集信息的示例。
http://www.c-sharpcorner.com/UploadFile/ravesoft/Page112282007015536AM/Page1.aspx http://www.c-sharpcorner.com/UploadFile/ravesoft/Page112282007015536AM/Page1.aspx
And you can load a specific assembly using [Assembly.Load()][1]
method. 您可以使用[Assembly.Load()][1]
方法加载特定的程序集。
This method might help you. 此方法可能会帮助您。
You need the name space "System.Reflection" to use the code below. 您需要名称空间“ System.Reflection”才能使用下面的代码。
//fileName = @"...\B.exe"; //The full path of the file you want to load
public string GetAssemblyProductName(string fileName)
{
Assembly fileAssembly = null;
try
{
fileAssembly = Assembly.LoadFile(fileName);//Loading Assembly from a file
}
catch (Exception error)
{
Console.WriteLine("Error: {0}", error.Message);
return string.Empty;
}
if (fileAssembly != null)
{
string productName = fileAssembly.GetName().Name;//This is for getting Product Name
//string productName = fileAssembly.GetName().FullName;//This is for getting Full Name
return productName;
}
else
{
Console.WriteLine("Error: Not valid assembly.");
return string.Empty;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.