Itiviti / gradle-msbuild-plugin

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

Regression in 2.13+: Builds fail with "the tools version is unrecognized" error. #68

Closed DKroot closed 6 years ago

DKroot commented 8 years ago

I have a build that runs find with plug-in 2.12. I'm using VS 2015 and MS Build 14.0.

Here is my full msbuild configuration:

msbuild {
        // .csproj, relative to the project root
        projectFile = file("src/main/asp.net/${vsProject}.csproj")

        // MsBuild project name (/p:Project=...)
        projectName = "${vsProject}"

        // Verbosity (/v:detailed, by default uses gradle logging level)
        //verbosity = 'detailed'

        // targets to execute (/t:Clean;Rebuild, no default)
        targets = ['Clean', 'Rebuild']

        // ### Project setting overrides ###

        // overrides project OutputPath
        destinationDir = "${buildDir}/msbuild/bin"

        // overrides project IntermediaryOutputPath
        intermediateDir = "${buildDir}/msbuild/obj"

        // Generates XML documentation file (from javadoc through custom DocLet)
        generateDoc = false

        // overrides project build configuration
        configuration = msbuildConfig

        // Other msbuild options can be set:
        // loggerAssembly, debugType, optimize, debugSymbols, platform, defineConstants ...

        // /Project setting overrides

        // ### Build properties (/p:SomeProperty=Value) ###

        parameters.DeployOnBuild = 'true'
        parameters.PublishProfile = 'Local Build Dir' // Publishes to build/site/
        parameters.VisualStudioVersion = '14.0' // VS 2015
    }

In 2.13+ builds fail with:

Error during project file parsing: Microsoft.Build.Exceptions.InvalidProjectFileException: The tools version "14.1" is unrecognized. Available tools versions are "14.0", "2.0", "3.5", "4.0".

This might have to do something with children projects. I have two child projects defined and configured in a similar way (to above). If I disable children projects, my main project passes.

adescamps-ullink commented 7 years ago

Hello,

I had the same issue until I changed the ToolsVersion="12.0" to ToolsVersion="14.0" in the csproj. This is because 12.0 is an unknown tools version so the plugin automatically bump to the tools version of MSBuild in the ProjectFileParser (i.e. 14.1).

Regards

Itzkwat commented 7 years ago

Hello all, I have just installed visual studio enterprise 2015 edition. I get the error attached when i tried to create a new project. 2017-02-09 1 I am new to visual studio and lost as to what to do next. Pls help

timotei commented 7 years ago

@Itzkwat That doesn't seem to be from this plugin, but rather from the project you're trying to open :)

duongphuhiep commented 7 years ago

I've got the same problem with 4.16. I use VS 2015 Community edition

Error during project file parsing: Microsoft.Build.Exceptions.InvalidProjectFileException: The tools version "14.1" is unrecognized. Available tools versions are "14.0", "2.0", "3.5", "4.0". D:\dev\Webservices\WonderLib\WonderLib.csproj at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args) at Microsoft.Build.Evaluation.Project.Data.InitializeForEvaluation(IToolsetProvider toolsetProvider) at Microsoft.Build.Evaluation.Evaluator4..ctor(IEvaluatorData4 data, ProjectRootElement projectRootElement, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary1 environmentProperties, ILoggingService loggingService, IItemFactory2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext, ProjectInstance projectInstanceIfAnyForDebuggerOnly) at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation) at Microsoft.Build.Evaluation.Project.Initialize(IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary2 globalProperties, String toolsVersion) at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName) at ProjectFileParser.ProjectHelpers.LoadProject(String fullPath, IDictionary2 args) at ProjectFileParser.ProjectHelpers.<>c__DisplayClass0_0.b__1(ProjectInSolution p) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at ProjectFileParser.ProjectHelpers.GetProjects(SolutionFile solution, IDictionary`2 args) at ProjectFileParser.Program.ParseSolution(String file, JObject args) at ProjectFileParser.Program.Parse(String file, JObject args) at ProjectFileParser.Program.Main(String[] args)

ngyukman commented 7 years ago

Did you try to update the csproj's ToolsVersion as per @adescamps-ullink 's comment?

duongphuhiep commented 7 years ago

No, I didn't.

I do not want to manually change these files (I have no trouble to open them in VS anyway)

Now I directly used command line MSBuild.exe mysolution.sln to build my solution

timotei commented 7 years ago

@ngyukman @adescamps-ullink I think we should take the highest of available, or maybe the closest to the one requested 🤔

JamesPoli commented 6 years ago

I've upgraded to com.ullink.gradle:gradle-msbuild-plugin:2.18 and am trying to build a simple vs2017 project (that, of course, builds in visual studio 17) and am getting the error above, i.e.; Error during project file parsing: Microsoft.Build.Exceptions.InvalidProjectFileException: The tools version "14.1" is unrecognized I too don't want to change a visual studio maintained file from ToolsVersion="15.0" to ToolsVersion="14.0". Where is the code that converts the "15.0" to "14.1"? Thanks in advance, Jim

ngyukman commented 6 years ago

hi @JamesPoli

can you test the latest plugin? There is a fix around the tools version in https://github.com/Ullink/gradle-msbuild-plugin/releases/tag/2.19

JamesPoli commented 6 years ago

Ok, will do! I'll post back with the results.

JamesPoli commented 6 years ago

Ng Yuk Man, that worked. I believe it was a red herring though, I had VS2017 Professional and Enterprise installed on my machine, and only used the Professional version. It appears code that looks for the VS version must have gotten mixed up. I completely uninstalled all VS2017 versions and re-installed only VS2017 Professional and it's all good.