'How to fix No valid value was specified for docker build context error in visual studio 2019

I've started a new .net 5 web app in vs 2019 with docker support. When I try to run it it throws the error "No valid value was specified for docker build context". Google isn't turning up anything on this. Anyone know how to fix this?

When I click on the error it takes me to this block of code in the container.targets file located at C:\Users\user\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.11.1\build. It references the line where <ContainerBuildAndLaunch starts.

<Target Name="ContainerBuildAndLaunch">
    <PropertyGroup>
      <LaunchContainer>false</LaunchContainer>
      <LaunchContainer Condition="Exists('$(ContainerSemaphoreFilePath)')">true</LaunchContainer>
      <ContainerDevelopmentMode Condition="'$(LaunchContainer)' != 'true'">Regular</ContainerDevelopmentMode> <!-- If we aren't building with intent to launch, always do full build -->
    </PropertyGroup>

    <ContainerBuildAndLaunch LaunchContainer="$(LaunchContainer)"
                             Dockerfiles="@(Dockerfile)"
                             ContainerDevelopmentMode="$(ContainerDevelopmentMode)"
                             IntermediateOutputPath="$(ContainerIntermediateOutputPath)"
                             ProjectCapability="@(ProjectCapability)"
                             ProjectFilePath="$(MSBuildProjectFullPath)"
                             NuGetPackageFolders="$(NuGetPackageFolders)"
                             NuGetPackageRoot="$(NuGetPackageRoot)"
                             TargetFramework="$(TargetFramework)"
                             TargetFrameworkIdentifier="$(TargetFrameworkIdentifier)"
                             TargetPath="$(TargetPath)"
                             ErrorLogFilePath="$(ContainerSemaphoreFilePath)"
                             DockerLabelBuiltImages="$(DockerLabelBuiltImages)"
                             ProjectTypeGuids="$(ProjectTypeGuids)"
                             OutputType="$(OutputType)"

                             DevEnvDir="$(DevEnvDir)"
                             VisualStudioVersion="$(VisualStudioVersion)"
                             ContainersToolsVersion="$(ContainersToolsVersion)"
                             AzureFunctionsVersion="$(AzureFunctionsVersion)"
                             FunctionsExecutionModel="$(FunctionsExecutionModel)"
                             ActiveDebugProfile="$(ActiveDebugProfile)"

                             DockerfileFile="$(DockerfileFile)"
                             DockerDefaultDockerfile="$(DockerDefaultDockerfile)"
                             DockerfileBuildArguments="$(DockerfileBuildArguments)"
                             DockerfileContext="$(DockerfileContext)"
                             DockerDefaultContext="$(DockerDefaultContext)"
                             DockerfileRepository="$(DockerfileRepository)"
                             DockerfileRunArguments="$(DockerfileRunArguments)"
                             ContainerVsDbgPath="$(ContainerVsDbgPath)"
                             DockerImageLabel="$(DockerImageLabel)"
                             DockerImageLabels="$(DockerImageLabels)"
                             DockerIncludeDefaultImageLabels="$(DockerIncludeDefaultImageLabels)"
                             DockerDefaultImageLabels="$(DockerDefaultImageLabels)"
                             DockerfileRunEnvironmentFiles="$(DockerfileRunEnvironmentFiles)"
                             DockerfileStage="$(DockerfileStage)"
                             DockerfileFastModeStage="$(DockerfileFastModeStage)"
                             DockerfileTag="$(DockerfileTag)"
                             DockerDefaultTag="$(DockerDefaultTag)"
                             DockerfileTargetOS="$(DockerfileTargetOS)"
                             DockerDefaultTargetOS="$(DockerDefaultTargetOS)"
                             UserSecretsId="$(UserSecretsId)"
                             DockerDebuggeeArguments="$(DockerDebuggeeArguments)"
                             DockerDebuggeeKillProgram="$(DockerDebuggeeKillProgram)"
                             DockerDebuggeeProgram="$(DockerDebuggeeProgram)"
                             DockerDebuggeeWorkingDirectory="$(DockerDebuggeeWorkingDirectory)"
                             DockerFastModeProjectMountDirectory="$(DockerFastModeProjectMountDirectory)"
                             BlazorStaticWebAssetsManifest="$(_GeneratedStaticWebAssetsDevelopmentManifest)">
      <Output TaskParameter="DockerfilesOut" ItemName="_Dockerfile" />
    </ContainerBuildAndLaunch>
  </Target>

Update: When I reopened this solution file I noticed in the output from the Container Tools in visual studio, the last line output was...

========== Verifying Docker OS ==========
Verifying that Docker Desktop's operating system mode matches the project's target operating system...
Docker Desktop's operating system mode matches the project's target operating system.
A non-critical error occurred while getting the container(s) ready. Your project(s) will continue to function normally. The error was: No valid value was specified for Docker build context.

It says that the project will function normally but clearly it doesn't.



Solution 1:[1]

This happened to me when I accidentally set the properties of the project: bad project proeperties

This corresponded to project file setting:

<DockerfileContext>not-correct-path</DockerfileContext>

Just deleting the value fixed it for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Oliver Clancy