MSBuild "The windows SDK version 10.0.19041.0 was not found" 即使已安装

MSBuild "The windows SDK version 10.0.19041.0 was not found" even though it's installed

我正在尝试使用 MSBuild 构建我的 Visual Studio 解决方案,我正在使用此命令来执行此操作: msbuild mysolution.sln /p:Configuration=Debug /p:PlatformToolset=v142

但是我收到以下错误:

C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VC\v160\Microsoft.Cpp.WindowsSDK.targets(46,5): error MSB8036: The Windows SDK version 10.0.19041.0 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [D:...\mysolution.vcxproj]

即使我在 Visual Studio 安装程序中安装了它并且 Visual Studio 可以毫无问题地使用它:

在 msbuild 修复它之前使用 vcvarsall.bat

"C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Auxiliary\Build\vcvarsall.bat" x86 10.0.19041.0

我认为您可能还需要在 msbuild 之前执行此操作: set UseEnv=true