设置 .NET Core 项目的版本号 [英] Setting the version number for .NET Core projects

查看:195
本文介绍了设置 .NET Core 项目的版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 .NET Core/ASP.NET Core 项目设置项目版本的选项有哪些?

What are the options for setting a project version with .NET Core / ASP.NET Core projects?

目前发现:

  • project.json 中设置 version 属性.来源:DNX 概览处理 DNX 项目.这似乎设置了 AssemblyVersionAssemblyFileVersionAssemblyInformationalVersion,除非被属性覆盖(见下一点).

  • Set the version property in project.json. Source: DNX Overview, Working with DNX projects. This seems to set the AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion unless overridden by an attribute (see next point).

设置AssemblyVersionAssemblyFileVersionAssemblyInformationalVersion 属性似乎也有效并覆盖versionproject.json 中指定的属性.

Setting the AssemblyVersion, AssemblyFileVersion, AssemblyInformationalVersion attributes also seems to work and override the version property specified in project.json.

例如,在project.json中包含'version':'4.1.1-*'并设置[assembly:AssemblyFileVersion("4.3.5.0")].cs 文件中将导致 AssemblyVersion=4.1.1.0AssemblyInformationalVersion=4.1.1.0AssemblyFileVersion=4.3.5.0

For example, including 'version':'4.1.1-*' in project.json and setting [assembly:AssemblyFileVersion("4.3.5.0")] in a .cs file will result in AssemblyVersion=4.1.1.0, AssemblyInformationalVersion=4.1.1.0 and AssemblyFileVersion=4.3.5.0

是否通过属性设置版本号,例如AssemblyFileVersion,还支持吗?

Is setting the version number via attributes, e.g. AssemblyFileVersion, still supported?

我错过了什么 - 还有其他方法吗?

Have I missed something - are there other ways?

我看到的场景是在多个相关项目之间共享一个版本号.一些项目使用 .NET Core (project.json),其他项目使用完整的 .NET Framework (.csproj).所有这些在逻辑上都是单个系统的一部分,并一起进行版本控制.

The scenario I'm looking at is sharing a single version number between multiple related projects. Some of the projects are using .NET Core (project.json), others are using the full .NET Framework (.csproj). All are logically part of a single system and versioned together.

到目前为止,我们使用的策略是在我们的解决方案的根目录中有一个 SharedAssemblyInfo.cs 文件,其中包含 AssemblyVersionAssemblyFileVersion 属性.这些项目包括指向文件的链接.

The strategy we used up until now is having a SharedAssemblyInfo.cs file at the root of our solution with the AssemblyVersion and AssemblyFileVersion attributes. The projects include a link to the file.

我正在寻找使用 .NET Core 项目实现相同结果的方法,即修改单个文件.

I'm looking for ways to achieve the same result with .NET Core projects, i.e. have a single file to modify.

推荐答案

在调用 buildpublish 时设置版本信息的另一个选项是使用未记录的 /p 选项.

Another option for setting version info when calling build or publish is to use the undocumented /p option.

dotnet 命令在内部将这些标志传递给 MSBuild.

dotnet command internally passes these flags to MSBuild.

示例:

dotnet publish ./MyProject.csproj /p:Version="1.2.3" /p:InformationalVersion="1.2.3-qa"

请参阅此处了解更多信息:https://github.com/dotnet/docs/issues/7568

See here for more information: https://github.com/dotnet/docs/issues/7568

这篇关于设置 .NET Core 项目的版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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