MSBuild could not be found if .Net 4.7.1 SDK is installed
Closed this issue · 11 comments
Plugin is unable to find msbuild v15+ on computer with:
- MS VS 2017 Build Tools installed (e.g. Visual Studio is not installed, just Build Tools)
- .Net SDK 4.7.1 installed
In this case plugin finds MSBuild v14 only (e.g. it will unable to build short new csproj projects)
hi, which version of gradle-msbuild-plugin are you using?
the latest version is new relying on vswhere 2.4.1 to get the msbuild
could you please check if you can get the msbuild from vswhere ?
For vswhere 2.4.1 (executed in PowerShell):
PS D:\temp> .\vswhere.exe -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools
For the latest vswhere (2.5.2):
PS D:\temp> & '.\vswhere (1).exe' -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools
For the vswhere 2.2.3:
PS D:\temp> & '.\vswhere (2).exe' -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools
Also: please note, that Gradle has private API for MSBuild location, please see here: https://github.com/gradle/gradle/blob/master/subprojects/ide-native/src/integTest/groovy/org/gradle/ide/visualstudio/fixtures/MSBuildVersionLocator.java
thanks, the one from gradle looks like to be just testing code that it won't be part of the production for now, but if gradle provide is out of the box we can consider it, though we have to avoid breaking change often
Regarding to your issue, seems the result looks fine, so meaning the gradle plugin should able to find the msbuild path from https://github.com/Ullink/gradle-msbuild-plugin/blob/4a6f101969649c32ed8182842a23a8f3ac809744/src/main/groovy/com/ullink/MsbuildResolver.groovy#L28
did you spot anything else when running inside your machine?
@ngyukman , yes, I set exact path to MSBuild folder and my builds work for now.
I'm using plugin with version 2.16
@imanushin so what's the error without setting the exact path when using 2.21?
@ngyukman , please see below. Build did not find MSBuild 15 and failed:
Execution failed for task ':****:msbuild'. org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe'' finished with non-zero exit value 1
Another option - possible it is better to check also environment variables below? TeamCity Agent sets them for all processes, so we can just reuse JetBrains lookup result:
Environment | variable Sample |
---|---|
MSBuildTools12.0_x64_Path | C:\Program Files (x86)\MSBuild\12.0\bin\amd64 |
MSBuildTools12.0_x86_Path | C:\Program Files (x86)\MSBuild\12.0\bin |
MSBuildTools14.0_x64_Path | C:\Program Files (x86)\MSBuild\14.0\bin\amd64 |
MSBuildTools14.0_x86_Path | C:\Program Files (x86)\MSBuild\14.0\bin |
MSBuildTools15.0_x64_Path | C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin\amd64 |
MSBuildTools15.0_x86_Path | C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin |
MSBuildTools2.0_x64_Path | C:\Windows\Microsoft.NET\Framework64\v2.0.50727 |
MSBuildTools2.0_x86_Path | C:\Windows\Microsoft.NET\Framework\v2.0.50727 |
MSBuildTools3.5_x64_Path | C:\Windows\Microsoft.NET\Framework64\v3.5 |
MSBuildTools3.5_x86_Path | C:\Windows\Microsoft.NET\Framework\v3.5 |
MSBuildTools4.0_x64_Path | C:\Windows\Microsoft.NET\Framework64\v4.0.30319 |
MSBuildTools4.0_x86_Path | C:\Windows\Microsoft.NET\Framework\v4.0.30319 |
a bit strange that vswhere success but gradle-msbuild-plugin is not getting that value
would be nice to catch the log
Found following MSBuild installation folder: ${msbuildDir}")
or
Found following MSBuild versions in the registry: ${availableVersions}
from the logic and your result it should be getting
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild
as result
if it's in env variable for your platform, you can easily apply it in build.gradle as a workaround
msbuild { msbuildDir = System.getenv('MSBuildTools15.0_x64_Path') }
I had a similar issue where after installing Visual Studio 2019, MSBuild was no longer found. I was using version 3.1, and changing that to 3.6 solved the issue for me.