Itiviti / gradle-msbuild-plugin

Gradle plugin for msbuild execution, supports C# project files for now
Apache License 2.0
101 stars 58 forks source link

MSBuild could not be found if .Net 4.7.1 SDK is installed #95

Closed imanushin closed 5 years ago

imanushin commented 6 years ago

Plugin is unable to find msbuild v15+ on computer with:

In this case plugin finds MSBuild v14 only (e.g. it will unable to build short new csproj projects)

ngyukman commented 6 years ago

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 ?

imanushin commented 5 years ago

@ngyukman, we are using the latest - 2.21

Will check soon ...

imanushin commented 5 years ago

@ngyukman,

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

ngyukman commented 5 years ago

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?

imanushin commented 5 years ago

@ngyukman , yes, I set exact path to MSBuild folder and my builds work for now.

I'm using plugin with version 2.16

ngyukman commented 5 years ago

@imanushin so what's the error without setting the exact path when using 2.21?

imanushin commented 5 years ago

@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
imanushin commented 5 years ago

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
ngyukman commented 5 years ago

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') }

Bodmoor commented 5 years ago

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.

ngyukman commented 5 years ago

the issue for visual studio 2019 was just fixed in 4d8779590f5d8a77d5a90e5b99053cf038d9ab9f

not sure if the fix also fixing this issue, closing it and feel free to create a new issue about this problem, and providing the chosen and expected msbuild path