【发布时间】:2017-09-02 14:38:23
【问题描述】:
这个问题和Setting the version number for .NET Core projects很相似,但又不一样。在撰写本文时使用最新稳定版本的 .NET Core (1.1) 和 VS2017,.NET Core 已从基于 JSON 的项目文件切换到 CSPROJ 文件。
所以 - 我想要做的是设置一个 CI 环境,我希望能够在构建之前修改 something 以用正确的版本号标记我的构建。 p>
如果我使用像这样的旧属性(SharedAssemblyInfo.cs 技巧):
[assembly: AssemblyFileVersion("3.3.3.3")]
[assembly: AssemblyVersion("4.4.4.4")]
在项目的某个地方,我得到了CS0579 - Duplicate 'System.Reflection.AssemblyFileVersionAttribute'
和CS0579 - Duplicate 'System.Reflection.AssemblyVersionAttribute'
构建时出错。
当深入研究它时,我发现\obj\Debug\netcoreapp1.1中有一个在构建过程中生成的文件(在我构建之前它不存在):
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("TestApplication")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyDescriptionAttribute("Package Description")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.1.99.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.1.99")]
[assembly: System.Reflection.AssemblyProductAttribute("TestApplication")]
[assembly: System.Reflection.AssemblyTitleAttribute("TestApplication")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.1.99.0")]
// Generated by the MSBuild WriteCodeFragment class.
问题 - 我该怎么做?
所以我可以看到这必须以某种方式从项目属性“包页面”中输入的值生成,但我不知道在我的 CI 机器上更改这些值的正确方法是什么。
理想情况下,我希望能够在我的 (Jenkins) CI 脚本中指定所有这些信息,但我会满足于设置版本号。
编辑 - 更多信息
在阅读了第一个答案后,我想明确表示我正在创建服务和 NuGET 包 - 我希望有一种对所有内容进行版本控制的方式,这就像我可以只更新单个文件的旧 JSON 项目.
更新 我正在编写脚本来更改 CSPROJ 文件,在我看来这很 hacky,因为我需要修改的部分看起来像这样......
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<Version>1.0.7777.0</Version>
<AssemblyVersion>1.0.8888.0</AssemblyVersion>
<FileVersion>1.0.9999.0</FileVersion>
<Company>MyCompany</Company>
<Authors>AuthorName</Authors>
<Product>ProductName</Product>
<Description />
<Copyright>Copyright © 2017</Copyright>
</PropertyGroup>
所以 - 这里的问题是有多个“PropertyGroup”元素;其他人似乎被贴上了标签——但不知道 CSPROJ 是如何组合在一起的,我不能说这种情况总是如此。
我的工作前提是始终填写包详细信息,否则 XML 中不会出现值标签(上图) - 所以我可以使用脚本来更新适当的值。如果值标签不存在,我将不清楚要将值插入哪个 PropertyGroup 元素(以及哪个顺序,因为这似乎很重要;更改顺序阻止了我在 VS2017 中加载项目)。
我仍在坚持寻找比这个更好的解决方案!
更新:在有人将此问题标记为可能重复 (Auto Versioning in Visual Studio 2017 (.NET Core)) 之后 - 我之前没有见过这个问题,现在阅读它似乎几乎相同,只是我不想设置版本号。此外,这个问题的答案并不能解决我的问题 - 只问我在我的问题中提出的问题。我的问题被接受的答案正是我需要解决我的问题的答案 - 所以虽然另一个问题首先出现并且看起来相同 - 它根本对我没有帮助。也许一个模组可以提供帮助?
【问题讨论】:
-
更新的答案包括解释 - 我没有看到那个帖子;它似乎是相同的,但它没有回答我的问题。这篇文章的公认答案完美地回答了我的问题。
标签: asp.net-core continuous-integration .net-core versioning