Hi, I have docker running on my computer and I was checking the Kubernetes extension.
I created a new project exactly as pointed on Create a new Kubernetes project step, then after the creation I right clicked on the DockerFile and clicked on Build Docker Image.
This is the result:
1>------ Rebuild All started: Project: Kubernetes1, Configuration: Debug Any CPU ------
1>Kubernetes1 -> c:\source\Kubernetes1\Kubernetes1\bin\Debug\netcoreapp2.1\Kubernetes1.dll
1>Kubernetes1 -> c:\source\Kubernetes1\Kubernetes1\bin\Debug\netcoreapp2.1\Kubernetes1.Views.dll
1>Docker version 18.06.1-ce, build e68fc7a
1>Sending build context to Docker daemon 2.47MB
1>
1>Step 1/16 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
1> ---> 1fe6774e5e9e
1>Step 2/16 : WORKDIR /app
1> ---> Using cache
1> ---> f32675e165c9
1>Step 3/16 : EXPOSE 80
1> ---> Using cache
1> ---> 5663c2407786
1>Step 4/16 : FROM microsoft/dotnet:2.1-sdk AS build
1> ---> 404c3ff21911
1>Step 5/16 : WORKDIR /src
1> ---> Using cache
1> ---> 0c544c108563
1>Step 6/16 : COPY ["Kubernetes1/Kubernetes1.csproj", "Kubernetes1/"]
1> ---> Using cache
1> ---> 3eb213a85178
1>Step 7/16 : RUN dotnet restore "$PROJECT_DIR/Kubernetes1.csproj"
1> ---> Running in 6f5213cc778a
1>MSBUILD : error MSB1001: Unknown switch.
1>Switch: /Kubernetes1.csproj
1>
1>For switch syntax, type "MSBuild /help"
1>The command '/bin/sh -c dotnet restore "$PROJECT_DIR/Kubernetes1.csproj"' returned a non-zero code: 1
1>C:\Users\merurino\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\0.18.1779678\build\Container.targets(144,5): error MSB3073: The command "docker build -t "kubernetes1" -f "c:\source\kubernetes1\kubernetes1\dockerfile" ".."" exited with code 1.
1>Done building project "Kubernetes1.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
I tried to build the dockerimage manually but get the same error. Am I missing something?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Hmm. MSBuild looks like it's seeing the path /Kubernetes1.csproj as a command line switch rather than as a folder path. It looks like there might be something funny about the value of $PROJECT_DIR. What is your project folder?
If the folder itself seems normal, try adding a pre-build step as described here:
https://stackoverflow.com/questions/3423538/how-can-i-find-out-the-value-of-projectdir
@lisaguthrie might be able to help.
Hi, the solution folder is: C:\source\Kubernetes1
And the project file would be: C:\source\Kubernetes1\Kubernetes1\Kubernetes1.csproj
I've added these to the pre-build script:
echo ProjectDir: $(ProjectDir)
echo PROJECT_DIR: $(PROJECT_DIR)
And they returned this:
1>ProjectDir: c:\source\Kubernetes1\Kubernetes1\
1>PROJECT_DIR:
Also, the errors in the error list are these:
Severity Code Description Project File Line Suppression State
Error MSB1001 Unknown switch. Kubernetes1 c:\source\Kubernetes1\Kubernetes1\[0mMSBUILD 1
And
Severity Code Description Project File Line Suppression State
Error MSB3073 The command "docker build -t "kubernetes1" -f "c:\source\kubernetes1\kubernetes1\dockerfile" ".."" exited with code 1. Kubernetes1 C:\Users\merurino\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\0.18.1779678\build\Container.targets 144
I also added a RUN "printenv" in one of the steps in docker and there's no project dir env variable.
1>Step 7/17 : RUN "printenv"
1> ---> Running in a882d279adf8
1>HOSTNAME=a882d279adf8
1>DOTNET_USE_POLLING_FILE_WATCHER=true
1>HOME=/root
1>DOTNET_RUNNING_IN_CONTAINER=true
1>DOTNET_SDK_VERSION=2.1.403
1>PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
1>ASPNETCORE_URLS=http://+:80
1>PWD=/src
1>NUGET_XMLDOC_MODE=skip
Is something failing to replace the PROJECT_DIR somehow?
Tried to add the full path instead of Project_Dir RUN dotnet restore "c:/source/Kubernetes1/Kubernetes1/Kubernetes1.csproj" But still got the issue that the project wasn't found, even though if I copy paste this it will open the project as it's exactly there. Considering docker will have only access from the folder you call it, I tried to change it to this:
RUN dotnet restore "Kubernetes1/Kubernetes1.csproj"
Now the build worked. Do you think this is an isolated case where my VS didn't replace the PROJECT_DIR variable in the file or something is not setting it as an env variable in docker or something?
I am able to reproduce this with 15.0.40524 and am working with the engineering team to resolve. This appears to be a product issue.
Closing this doc issue. The product issue has been acknowledged.
I faced the same issue, Just move the dockerfile one level up
for example your current csproj path is
c:\projects\MySolutionFolder\MyProj\MyProj.csproj (Where docker file is here as well)
Move the docker file to be in "c:\projects\MySolutionFolder\"
I hop it helps you.