【问题标题】:Set Assembly version of net core app using Azure DevOps with a DockerFile使用带有 DockerFile 的 Azure DevOps 设置网络核心应用程序的程序集版本
【发布时间】:2020-06-21 20:24:30
【问题描述】:

我正在使用由 Visual Studio 创建的 DockerFile 来创建我的图像。我想使用 Azure DevOps 构建并将我的程序集版本设置为我在管道中的版本。我觉得我必须改变这条线,但我不知道如何。

    RUN dotnet build "ImportBatch.Api.csproj" -c Release -o /app/build

我的 Docker 文件

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["ImportBatch.Api/ImportBatch.Api.csproj", "ImportBatch.Api/"]
COPY ["ImportBach.Dto/ImportBatch.Dto.csproj", "ImportBach.Dto/"]
COPY ["Common/Common.csproj", "Common/"]
COPY ["Common.Dto/Common.Dto.csproj", "Common.Dto/"]
COPY ["Common.Azure.Storage/Common.Azure.Storage.csproj", "Common.Azure.Storage/"]
RUN dotnet restore "ImportBatch.Api/ImportBatch.Api.csproj"
COPY . .
WORKDIR "/src/ImportBatch.Api"
RUN dotnet build "ImportBatch.Api.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ImportBatch.Api.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Cardinal.Software.ImportBatch.Api.dll"]

【问题讨论】:

  • 无法获得您的最新信息,Krzysztof Madej 的解决方法对您有帮助吗?或者,如果您有任何疑虑,请随时在此处分享。
  • 有了这个下一个问题是如何将 1.2.3.4(版本号)从 azure devops 传递到 dockerfile

标签: asp.net-core azure-devops dockerfile


【解决方案1】:

对于 SDK 风格的项目,程序集版本属性是自动生成的,因此您可以直接使用 p:Version=1.2.3.4。请查看示例here(在底部)

dotnet build -p:Version=1.2.3.4

【讨论】:

    【解决方案2】:

    来自管道:

    - task: Docker@1
      displayName: 'Build the image'
      inputs:
        dockerfile: 'Dockerfile'
        imageName: '$(imageRepoName):$(GitVersion.SemVer)'
        arguments: '--build-arg version=$(GitVersion.SemVer)'
      continueOnError: true
    

    在 DockerFile 上:

    FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build
    WORKDIR /src
    COPY . .
    ARG version  #define the argument
    #use this argument while running build or publish, for example
    RUN dotnet publish "./yourProject.csproj" -c Release /p:Version=${version} -o /app/publish --no-restore
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-13
      • 1970-01-01
      相关资源
      最近更新 更多