title: CS0016 using dotnet build/publish with --output parameter when running in Server Core Docker EE container
body: <p>I have a Windows docker container running on Server Core with Docker EE. When I try and run <code>dotnet build</code> or <code>dotnet publish</code>, I get a CS0016 'Could not write to output file' error.</p>
  <p>This is the Dockerfile:</p>
  <pre><code>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 [&quot;dotnet&quot;, &quot;API.Core.dll&quot;]
  </code></pre>
  <p>Running interactively inside the container, I can see all of the source files are in C:\src</p>
  <pre><code>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]
  </code></pre>
  <p>What I find odd is that the path to the 'output file' isn't C:\app\API.Core.Service\xmldocs.xml - it's as if the <code>--output</code> parameter is being ignored.</p>
  <p>Things I've tried:</p>
  <ul>
  <li>Using dotnet build instead of dotnet publish</li>
  <li>Using an absolute path - C:\app instead of /app</li>
  <li>Removing the output parameter, which should then default to (projectDir)/bin</li>
  <li>Verifying the C:\app directory exists</li>
  <li>Verifying C:\src\API.Core.Service\xmldocs.xml exists</li>
  <li>Running build/publish against the .sln file</li>
  </ul>
  <p>Building the Dockerfile and running the container works fine on my laptop running Docker Desktop.</p>
  <p>Is the error message misleading and 'output file' is really the source file?</p>
  <p>Most of this is copied and tweaked from the MS docs at <a href="https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images?view=aspnetcore-5.0" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images?view=aspnetcore-5.0</a></p>