如何修复 Visual Studio 2019 中的 docker 构建上下文错误未指定有效值

geo*_*rtz -1 docker .net-5

我在 vs 2019 中启动了一个新的 .net 5 Web 应用程序,并支持 docker。当我尝试运行它时,它会抛出错误“没有为 docker 构建上下文指定有效值”。谷歌没有透露任何有关此事的信息。有人知道怎么修这个东西吗?

当我单击错误时,它会将我带到位于 C:\Users\user\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.11.1\ 的container.targets 文件中的这段代码。建造。它引用 <ContainerBuildAndLaunch 开始的行。

<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>
Run Code Online (Sandbox Code Playgroud)

更新:当我重新打开此解决方案文件时,我注意到 Visual Studio 中容器工具的输出中,最后一行输出是...

========== 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.
Run Code Online (Sandbox Code Playgroud)

它说该项目将正常运行,但显然事实并非如此。

Oli*_*ncy 5

当我不小心设置项目的属性时,就发生了这种情况: 糟糕的项目属性

这对应于项目文件设置:

<DockerfileContext>not-correct-path</DockerfileContext>
Run Code Online (Sandbox Code Playgroud)

只需删除该值就可以修复它。