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

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

问题描述

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

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

到目前为止已发现:


  • 设置<$ c $ project.json 中的c> version 属性。来源: DNX概述使用DNX项目。这似乎设置了 AssemblyVersion AssemblyFileVersion AssemblyInformationalVersion ,除非

  • 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).

设置 AssemblyVersion AssemblyFileVersion AssemblyInformationalVersion 属性似乎也可以正常工作,并覆盖在 version 属性中指定的 project.json

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

例如,在中包括'version':'4.1.1-*' project.json 并在 .cs [assembly:AssemblyFileVersion( 4.3.5.0)] c $ c>文件将导致 AssemblyVersion = 4.1.1.0 AssemblyInformationalVersion = 4.1.1.0 AssemblyFileVersion = 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 文件位于我们解决方案的根目录,具有 AssemblyVersion AssemblyFileVersion 属性。这些项目包括指向文件的链接。

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.

推荐答案

调用 build publish 将使用未记录的 / 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天全站免登陆