为什么通过 VS 开发人员控制台使用 MSBuild 工作正常,但通过 powershell 它要我安装 Windows SDK?
Why using MSBuild via VS Developer Console works fine, but via powershell it wants me to install Windows SDK?
当我通过 Power 编译项目时Shell:
PS C:\Windows\Microsoft.NET\Framework64\v4.0.30319> .\MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj"
然后就失败了
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(2015,5): error MSB3091:
ask failed because "AxImp.exe" was not found, or the correct Microsoft Windows SDK is not installed. The task is looking for "AxImp.exe" in the "bin" subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools-x86. You may be able to solve the problem by doing one of the following: 1) Install the Microsoft Windows SDK. 2) Install Visual Studio 2010. 3) Manually set the above registry key to the correct location. 4) Pass the correct location into the "ToolPath" parameter of the task."
但是当我通过 VS 开发人员命令提示为 VS2019
执行此操作时
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.4.3
** Copyright (c) 2019 Microsoft Corporation
**********************************************************************
C:\Windows\System32>MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj"
那就完美了!
但是,如您所见,当前路径(MS Build 的文件夹)完全不同,所以我再次尝试在 PowerShell 中使用 VS Dev CMD 的位置执行此操作:
PS C:\Windows\System32> cd "C:\Windows\System32"
PS C:\Windows\System32> MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj"
MSBuild.exe : The term 'MSBuild.exe' is not recognized as the name of a cmdlet, function, script file, or operable prog
ram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj" ...
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (MSBuild.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Windows\System32>
这是怎么回事?为什么我可以从 Developer CMD 完美地编译我的项目,而我不能用 Power Shell 编译我的项目并且它尖叫说我没有 Windows SDK?
或者我应该使用哪个 MS Build(显然有几个)?
我发现使用 MSBuild 来自:
"C:\Program Files (x86)\Microsoft Visual Studio19\Professional\MSBuild\Current\Bin\MSBuild.exe"
工作正常,所以显然 VS Dev CMD 使用的 MSBuild
与 C:\Windows\Microsoft.NET\Framework64\v4.0.30319
中的不同
破案(对我来说)
当我通过 Power 编译项目时Shell:
PS C:\Windows\Microsoft.NET\Framework64\v4.0.30319> .\MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj"
然后就失败了
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(2015,5): error MSB3091: ask failed because "AxImp.exe" was not found, or the correct Microsoft Windows SDK is not installed. The task is looking for "AxImp.exe" in the "bin" subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools-x86. You may be able to solve the problem by doing one of the following: 1) Install the Microsoft Windows SDK. 2) Install Visual Studio 2010. 3) Manually set the above registry key to the correct location. 4) Pass the correct location into the "ToolPath" parameter of the task."
但是当我通过 VS 开发人员命令提示为 VS2019
执行此操作时**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.4.3
** Copyright (c) 2019 Microsoft Corporation
**********************************************************************
C:\Windows\System32>MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj"
那就完美了!
但是,如您所见,当前路径(MS Build 的文件夹)完全不同,所以我再次尝试在 PowerShell 中使用 VS Dev CMD 的位置执行此操作:
PS C:\Windows\System32> cd "C:\Windows\System32"
PS C:\Windows\System32> MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj"
MSBuild.exe : The term 'MSBuild.exe' is not recognized as the name of a cmdlet, function, script file, or operable prog
ram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj" ...
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (MSBuild.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Windows\System32>
这是怎么回事?为什么我可以从 Developer CMD 完美地编译我的项目,而我不能用 Power Shell 编译我的项目并且它尖叫说我没有 Windows SDK?
或者我应该使用哪个 MS Build(显然有几个)?
我发现使用 MSBuild 来自:
"C:\Program Files (x86)\Microsoft Visual Studio19\Professional\MSBuild\Current\Bin\MSBuild.exe"
工作正常,所以显然 VS Dev CMD 使用的 MSBuild
与 C:\Windows\Microsoft.NET\Framework64\v4.0.30319
破案(对我来说)