.net 读取项目AssemblyInfo.cs属性值
要在.NET中读取项目的AssemblyInfo.cs文件中的属性值,可使用System.Reflection命名空间中的Assembly类。
以下是一个示例代码,它演示怎样读取AssemblyInfo.cs文件中的AssemblyTitle属性值:
```csharp
using System;
using System.Reflection;
class Program
{
static void Main()
{
// 获得当前程序集的Assembly对象
Assembly assembly = Assembly.GetExecutingAssembly();
// 获得AssemblyTitle属性值
string assemblyTitle = assembly.GetCustomAttribute()?.Title;
// 打印AssemblyTitle属性值
Console.WriteLine("Assembly Title: " + assemblyTitle);
}
}
```
上述代码首先通过`Assembly.GetExecutingAssembly()`方法获得当前程序集的`Assembly`对象。然后,它使用`GetCustomAttribute
请注意,`GetCustomAttribute
这只是一个示例,你可以根据自己的需要修改代码来读取其他属性值。
TOP