【发布时间】:2021-03-29 12:56:46
【问题描述】:
我有一个使用 Docker EE 在 Server Core 上运行的 Windows docker 容器。当我尝试运行 dotnet build 或 dotnet publish 时,我收到 CS0016 'Could not write to output file' 错误。
这是 Dockerfile:
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app
EXPOSE 5000
EXPOSE 5001
# copy csproj and restore as distinct layers
WORKDIR /src
COPY *.sln ./
COPY nuget.config ./
COPY API.Core/*.csproj ./API.Core/
COPY API.Core.Service/*.csproj ./API.Core.Service/
RUN dotnet restore
# copy everything else and build app
COPY . .
RUN dotnet publish API.Core/API.Core.csproj -c release -o /app --no-restore
# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS final
WORKDIR /app
COPY --from=build /app ./
ENTRYPOINT ["dotnet", "API.Core.dll"]
在容器内交互运行,我可以看到所有的源文件都在 C:\src
dotnet publish API.Core/API.Core.csproj -c release --output /app
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
CSC : error CS0016: Could not write to output file 'C:\src\API.Core.Service\xmldocs.xml' -- 'Access to the path 'C:\
src\API.Core.Service\xmldocs.xml' is denied.' [C:\src\API.Core.Service\API.Core.Service.csproj]
我觉得奇怪的是“输出文件”的路径不是 C:\app\API.Core.Service\xmldocs.xml - 就好像 --output 参数被忽略了一样。
我尝试过的事情:
- 使用 dotnet build 而不是 dotnet publish
- 使用绝对路径 - C:\app 而不是 /app
- 删除输出参数,然后默认为 (projectDir)/bin
- 验证 C:\app 目录是否存在
- 验证 C:\src\API.Core.Service\xmldocs.xml 是否存在
- 针对 .sln 文件运行构建/发布
在我运行 Docker Desktop 的笔记本电脑上构建 Dockerfile 并运行容器可以正常工作。
错误信息是否具有误导性,“输出文件”真的是源文件吗?
其中大部分内容是从https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images?view=aspnetcore-5.0 的 MS 文档中复制和调整的
【问题讨论】:
标签: .net windows docker .net-core