Am facing strange issue. When i build my Dockerfile
on windows machine(Laptop) getting below error and also getting same error when i tried to deploy on 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>
But the same Dockerfile
works fine when we build it using visual studio it builds and starts running without any errors.
Docker file looks like:
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"]
Because in your dotnet restore
there is /
so MSBuild think it's a switch (like /p:
) and fails, you just need to remove it:
RUN dotnet restore "WebApp.csproj"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With