MSBuild笔记-预留
属性
程序集特性
.NET Core 2.1之前程序集特性存储在AssemblyInfo 文件中,2.1开始程序集特性移到MSBuild属性中
属性 | Property | 要禁用的属性 |
---|---|---|
AssemblyCompanyAttribute | Company | GenerateAssemblyCompanyAttribute |
AssemblyConfigurationAttribute | Configuration | GenerateAssemblyConfigurationAttribute |
AssemblyCopyrightAttribute | Copyright | GenerateAssemblyCopyrightAttribute |
AssemblyDescriptionAttribute | Description | GenerateAssemblyDescriptionAttribute |
AssemblyFileVersionAttribute | FileVersion | GenerateAssemblyFileVersionAttribute |
AssemblyInformationalVersionAttribute | InformationalVersion | GenerateAssemblyInformationalVersionAttribute |
AssemblyProductAttribute | Product | GenerateAssemblyProductAttribute |
AssemblyTitleAttribute | AssemblyTitle | GenerateAssemblyTitleAttribute |
AssemblyVersionAttribute | AssemblyVersion | GenerateAssemblyVersionAttribute |
NeutralResourcesLanguageAttribute | NeutralLanguage | GenerateNeutralResourcesLanguageAttribute |
使用方式如下: |
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<Version>1.2.3.4</Version>
<Authors>Author 1</Authors>
<Company>Company XYZ</Company>
<Product>Product 2</Product>
<PackageId>MyApp</PackageId>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>3.0.0.0</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
<Description>Description here</Description>
<Copyright>Copyright</Copyright>
<PackageLicenseUrl>License URL</PackageLicenseUrl>
<PackageProjectUrl>Project URL</PackageProjectUrl>
<PackageIconUrl>Icon URL</PackageIconUrl>
<RepositoryUrl>Repo URL</RepositoryUrl>
<RepositoryType>Repo type</RepositoryType>
<PackageTags>Tags</PackageTags>
<PackageReleaseNotes>Release</PackageReleaseNotes>
</PropertyGroup>
可以在程序中读取程序集特性
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
string title = titleAttribute.Title;
}
}
参考:https://docs.microsoft.com/zh-cn/dotnet/core/migration/assembly-info?view=aspnetcore-5.0