使用 .NET Core 时是否需要 AssemblyInfo? [英] Do I need AssemblyInfo while working with .NET Core?

查看:36
本文介绍了使用 .NET Core 时是否需要 AssemblyInfo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,AssemblyInfo.cs 文件由 Visual Studio 自动创建,以包含程序集范围的属性,如 AssemblyVersion、AssemblyName 等.

Previously, AssemblyInfo.cs file was autocreated by Visual Studio to contain assembly-wide attributes, like AssemblyVersion, AssemblyName and so on.

在 .NET Core 和 ASP.NET Core 中,project.json 负责保存大部分信息.

In .NET Core and ASP.NET Core, project.json is responsible for holding most of that information.

所以问题是:我是否需要再用这些属性来标记我的程序集?如果我不使用该属性标记程序集,我会陷入什么陷阱?

So the question is: do I need to mark my assemblies with that attributes anymore? What traps can I get in if I will not mark assembly with that attributes?

推荐答案

project.json 已经替换了 AssemblyInfo.

AssemblyVersionAttribute 替换为 version 属性

version
Type: String
The Semver version of the project, also used for the NuGet package.

AssemblyNameAttribute 现在是 name 属性

name
Type: String
The name of the project, used for the assembly name as well as the name of the package. The top level folder name is used if this property is not specified.

等等

更新:随着 .NET Core Tools MSBuild 的发布,.csproj 取代了 project.json.AssemblyInfo.cs 文件又回来了,但大部分设置已直接移至 .csproj.有关更多详细信息,请参阅相关 SO 问题:相当于 dotnet core/csproj 中的 AssemblyInfo:

Update: With the announcement of .NET Core Tools MSBuild, the .csproj has replaced the project.json. The AssemblyInfo.cs file is back, but most of the settings have been moved directly to .csproj. See related SO question for more details: Equivalent to AssemblyInfo in dotnet core/csproj :

<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>

这篇关于使用 .NET Core 时是否需要 AssemblyInfo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆