Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker fails to build in Azure Pipelines with "error MSB1001"

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"]
like image 403
Prateek Naik Avatar asked May 29 '19 07:05

Prateek Naik


1 Answers

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"
like image 162
Shayki Abramczyk Avatar answered Nov 08 '22 15:11

Shayki Abramczyk