问题描述
使用.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 属性。来源:,。这似乎设置了 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 $ c $时用于设置版本信息的另一个选项c>将使用未记录的 / 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"
有关更多信息,请参见此处:
See here for more information: https://github.com/dotnet/docs/issues/7568
这篇关于设置.NET Core项目的版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!