繁体   English   中英

确保 azure 管道构建的 dll 和 nuget 包包含与 csproj 版本相同的信息

[英]Ensuring azure pipeline built dll and nuget package contain same info as csproj version

我正在重新发布一个特定问题,因为我知道除了azure-pipelines.yml之外还需要一个 powershell 脚本。

我将如何使用 azure 管道实现相同的输出/格式以在输出文件中提供以下版本控制(以及每个https://www.nuget.org/packages/MediatR/匹配的 nuget 包信息)。

dll 属性

我知道这将是一个 powershell 脚本,我已经检查了 MediatR 并查看了https://github.com/jbogard/MediatR/blob/master/Build.ps1但看不到我将如何将其应用于 azure 管道步骤.

总之,应该使用来自我的 csproj 的 verisn 前缀<VersionPrefix>1.0.1</VersionPrefix> (或任何版本),并应用于二进制 dll 和 nuget 包中的文件版本属性。

我还想将 dll 的产品版本设置为特定的构建日期时间(或在 MediatR 的情况下使用的提交字符串)。

我特别在寻找一个脚本(powershell 和关联的 yaml 来链接脚本版本字符串)和相关的步骤,感谢一个大问题,但是我在 google 或 Stackorerflow 上找不到任何具体的答案 - 一个教程的链接将是完美的。

指针赞赏。

总之,应该使用来自我的 csproj 的 1.0.1(或任何版本)的 verisn 前缀,并应用于二进制 dll 和 nuget 包中的文件版本属性。

我还想将 dll 的产品版本设置为特定的构建日期时间(或在 MediatR 的情况下使用的提交字符串)。

除了 PowerShell 方向,我们可以考虑将msbuild 属性作为另一个方向。

这是我的test.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <!--Add other properties here.-->
  </PropertyGroup>

  <PropertyGroup> <!--Custom Property Group for CI/CD-->
    <MyVersionPrefix>1.0.1</MyVersionPrefix>
    <MyVersionSuffix>0</MyVersionSuffix>
    <BuildDateTime>0</BuildDateTime>
    <AssemblyVersion>$(MyVersionPrefix).$(MyVersionSuffix)</AssemblyVersion> <!--File Version-->
    <Version>$(MyVersionPrefix).$(BuildDateTime)</Version> <!--Product Version-->
    <PackageVersion>$(MyVersionPrefix).$(MyVersionSuffix)</PackageVersion> <!--Nuget Package Version-->
    <Copyright>Just for test.</Copyright>
  </PropertyGroup>
</Project>

我有一个自定义属性组来定义File Version, Product Version and Package Version.等属性File Version, Product Version and Package Version. 我没有使用<VersionPrefix>1.0.1</VersionPrefix> ,而是使用自定义的<MyVersionPrefix>1.0.1</MyVersionPrefix>

这可以很好地恢复,在本地开发中构建。 如果您还需要在本地打包项目,您可以评论(使用<----> )这个属性组。

要使用 CI/CD 配置此项目:

我的意见是覆盖xx.csproj定义的属性。 对我来说,我创建了一个Suffix管道变量:

在此处输入图片说明

然后将管道内部版本号格式设置为: $(date:yyyyMMdd)$(rev:r)

然后我像这样指定dotnet build taskdotnet pack task

- task: DotNetCoreCLI@2
      displayName: "Build Solution"
      inputs:
        command: build
        projects: '**/*.csproj'
        arguments: '--configuration $(BuildConfiguration) -p:MyVersionSuffix=$(Suffix) -p:BuildDateTime=$(Build.BuildNumber)'

- task: DotNetCoreCLI@2
      displayName: 'dotnet pack'
      inputs:
        command: pack
        nobuild: true
        buildProperties: 'MyVersionSuffix=$(Suffix)'

通过这种方式,我可以将$(Suffix)$(Build.BuildNumber)从构建管道传递给 msbuild 命令。 我可以通过管道变量控制file version, product version, nuget package version (关于文件、产品、包版本的对应属性见我上面的项目文件。)

如果将 Suffix 变量设置为19 ,那么在构建和打包之后,我可以得到一个包版本为1.0.1.19的 Nuget 包。 其中程序集具有相同的文件版本1.0.1.19和产品版本,如1.0.1.202001208 如果您不想要一个不断增加的产品版本,则可以使用以下命令在构建任务中指定所需的值: -p:BuildDateTime=AnyValueYouWant

希望它有所帮助,如果我误解了什么,请随时纠正我:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM