【问题标题】:How to update only version info in assemblyinfo.cs using cake?如何使用 cake 仅更新 assemblyinfo.cs 中的版本信息?
【发布时间】:2017-03-15 20:18:09
【问题描述】:

我对 cakebuild 很陌生。我想使用 cakebuild 更新 assemblyinfo.cs 的版本信息。

public static void CreateAssemblyInfo() 方法覆盖了 assemblyinfo 文件的全部内容。但我只需要更新版本信息。

我怎样才能做到这一点?

问候, 阿拉迪亚

【问题讨论】:

    标签: c# cakebuild


    【解决方案1】:

    如果您不想拥有单独的文件,您也可以使用正则表达式替换:

    #addin "Cake.FileHelpers"
    var yourVersion = "1.0.0.0";
    
    Task("SetVersion")
       .Does(() => {
           ReplaceRegexInFiles("./your/AssemblyInfo.cs", 
                               "(?<=AssemblyVersion\\(\")(.+?)(?=\"\\))", 
                               yourVersion);
       });
    

    根据您的 AssemblyInfo 文件,您可能还需要替换 AssemblyFileVersionAssemblyInformationalVersion 的值

    【讨论】:

      【解决方案2】:

      有 2 个文件,一个用于静态文件,一个用于自动生成的位。

      我通常应用的模式是在项目之间共享一个SolutionInfo.cs,每个项目都有一个AssemblyInfo.cs,每个项目都是唯一的。

      一个示例文件夹结构可以是

      src
      |    Solution.sln
      |    SolutionInfo.cs
      |    
      \--- Project
          |   Project.csproj
          |
          \---Properties
                  AssemblyInfo.cs
      

      基本上你的 csproj 文件会代替:

      <Compile Include="Properties\AssemblyInfo.cs" />
      

      是这样的:

      <Compile Include="Properties\AssemblyInfo.cs" />
      <Compile Include="..\SolutionInfo.cs">
        <Link>Properties\SolutionInfo.cs</Link>
      </Compile>
      

      这样您就可以保留对 AssemblyInfo.cs 的任何手动编辑,并且可以安全地自动生成,而不会有覆盖该信息的风险。

      这还允许您在解决方案中的项目之间共享版本/版权/公司等内容。

      其中的 Cake 构建脚本部分如下所示:

      Task("SolutionInfo")
          .IsDependentOn("Clean")
          .IsDependentOn("Restore")
          .Does(() =>
      {
          var file = "./src/SolutionInfo.cs";
          CreateAssemblyInfo(file, assemblyInfo);
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-08-11
        • 2010-09-18
        • 1970-01-01
        • 2020-01-31
        • 1970-01-01
        • 1970-01-01
        • 2019-01-11
        • 1970-01-01
        相关资源
        最近更新 更多