whatever
whatever

Reputation: 3707

NuGet MSBuild auto-detection finding MSBuild under TeamExplorer?

I'm building from the command line a visual studio solution and the MSBuild auto-detection procedure is finding msbuild under TeamExplorer which makes the build fail as the needed *.targets files are afterwards not found. I don't have the msbuild under TeamExplorer in PATH env variable and even when running the developer command prompt for VS2019 I only see the msbuild instance under Enterprise (visual studio enterprise edition) in PATH. How/why is the msbuild under TeamExplorer found instead of the one under VS enterprise?

In the logs I see the following when attempting to build a csproj and then it fails picking the wrong msbuild instance

Looking for VS 16 installation
MsBuild referenced at: C:\Program Files (x86)\Microsoft Visual Studio\2019\TeamExplorer C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise \MSBuild\Current\Bin\MSBuild.exe

Upvotes: 3

Views: 9289

Answers (2)

whatever
whatever

Reputation: 3707

I investigated in detail the build process and I discovered that msbuild was invoked via powershell (start-process) enumerating the visual studio instances via cmdlets (Get-VSSetupInstance) provided by the VSSetup powershell module and unfortunately it was not expected to find two visual studio instances on the machine (in my case TeamExplorer and VS 2019 Enterprise) and unfortunately the script ended up selecting the first instance returned. I'm now filtering out TeamExplorer and everything works fine. Thank you for your support.

Upvotes: 2

Mr Qian
Mr Qian

Reputation: 23838

If you run msbuild.exe directly from CMD, you should check your environment variable PATH carefully and make sure that you did not specify another wrong version of msbuild.exe. And delete the wrong folder which the wrong version of msbuild.exe exists.

The right version of msbuild.exe exists under

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe

I think you should input the path C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin into the System environment variable PATH.

Also, according to the principle of first get first use of PATH, you should place this path at the beginning of PATH and test it again.

In my side, I only have vs community version and the below is a sample:

enter image description here

Remember to click OK.

If it does not work, please provide more info about your steps of calling msbuild.exe, whether you can build the project under VS IDE, ......

Upvotes: 1

Related Questions