我面临着奇怪的问题。当我在Windows计算机(笔记本电脑)上构建Dockerfile
时,出现以下错误,并且尝试在Azure DevOps
上进行部署时也遇到了相同的错误。
Step 7/17 : COPY ["WebApp.csproj", ""]
---> 3f3e198d00aa
Step 8/17 : RUN dotnet restore "/WebApp.csproj"
---> Running in 51f16f947ffb
MSBUILD : error MSB1001: Unknown switch.
Switch: /WebApp.csproj
For switch syntax, type "MSBuild -help"
The command '/bin/sh -c dotnet restore "/WebApp.csproj"' returned a non-zero code: 1
PS C:\Users\user\Desktop\Directory>
但是当我们使用 Visual Studio 构建它时,同样的Dockerfile
可以很好地运行,并且可以正常运行。
Docker文件如下:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["WebApp.csproj", ""]
RUN dotnet restore "/WebApp.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "WebApp.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "WebApp.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApp.dll"]
答案 0 :(得分:3)
由于您的dotnet restore
中有/
,因此MSBuild认为它是一个开关(如/p:
)并且失败了,您只需要删除它即可:
RUN dotnet restore "WebApp.csproj"