asp.net-core - 使用带有 DockerFile 的 Azure DevOps 设置网络核心应用程序的程序集版本

标签 asp.net-core azure-devops dockerfile

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

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

我的 DockerFile

#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"]

最佳答案

来自管道:

- 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

关于asp.net-core - 使用带有 DockerFile 的 Azure DevOps 设置网络核心应用程序的程序集版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62504004/

相关文章:

c# - 多次创建 ASP.NET Core 单例服务

asp.net - 如何找到asp.net核心版本

c# - 如何从 .Net Core Web API 返回 Unauthorized

c# - 如何在使用 Docker 时为 NuGet 配置代理?

ruby-on-rails - Rails Assets :precompile is using wrong bundler version

c# - 物理文件提供程序返回 404

c# - 在 Azure DevOps 上显示 NUnit 测试代码覆盖率

Azure DevOps 托管构建代理 MSI

azure - 如何从 Azure Devops Cli 获取标签日期

bash - 如何在启动时动态地将docker容器ip设置为环境变量?