我的.csproj文件包含:
...
<PackageId>MyProject</PackageId>
<Version>1.0.0</Version>
...
Run Code Online (Sandbox Code Playgroud)
我如何从我的项目代码中访问它?
要访问项目的版本和更常规的属性,请使用:
GetCustomAttribute<T>()
用作AssemblyInformationalVersionAttribute类型 T 来检索 Version 属性。
有关 T 的其他值,请参阅https://learn.microsoft.com/en-us/dotnet/api/system.reflection?view=netcore-2.0上列出的属性
例子:
typeof(Startup).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion
| 归档时间: |
|
| 查看次数: |
2135 次 |
| 最近记录: |