dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

Error after updating Visual Studio 2017 to v15.8.2 when running unit tests: Method 'Microsoft.Build.Utilities.ToolLocationHelper.GetPathToStandardLibraries' not found #3733

Open mgmccarthy opened 6 years ago

mgmccarthy commented 6 years ago

Posted in developercommunity.visualstudio.com as well: https://developercommunity.visualstudio.com/content/problem/333202/error-after-updating-to-1582-when-running-unit-tes.html

After upgrading to Visual Studio 2017 v15.8.2 and running rosyln-based unit tests, they all fail.

The failure is on the line of code at workspace.Diagnostics.Any query:

[SetUpFixture]
public class SolutionSetup
    {
    [OneTimeSetUp]
    public async Task Load()
    {
        EnsureMsBuildCanBeFound();
        var solutionPath = GetSolutionPath();
        var workspace = MSBuildWorkspace.Create();
        Solution = await workspace.OpenSolutionAsync(solutionPath);

        if (workspace.Diagnostics.Any(d => !d.Message.Contains("If you have not done a build you can ignore this error")))
            Assert.Fail($"Failed to load solution: {string.Join(", ", workspace.Diagnostics.Select(d => d.Message))}");
        ...
        }
...
}

Full stack trace: Msbuild failed when processing the file 'D:\Projects\IXRS\Study\IXRS.Client.Web.Tests\IXRS.Client.Web.Tests.csproj' with message: Invalid static method invocation syntax: "[Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries($(TargetFrameworkIdentifier), $(TargetFrameworkVersion), $(TargetFrameworkProfile), $(PlatformTarget), $(TargetFrameworkRootPath), $(TargetFrameworkFallbackSearchPaths))". Method 'Microsoft.Build.Utilities.ToolLocationHelper.GetPathToStandardLibraries' not found. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(a, b)). C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets

Things I've Tried

Update Microsoft.CodeAnalysis package from 2.6.1 to 2.9.0 (and all subsequent dependencies that go along with that package). image

This didn't work as once the upgrade was done, the compiler threw an exception that is no longer recognized MSBuildWorkspace image

I then went out to find the missing NuGet package (where MSBuildWorkspace was moved to) and installed it: image

the compiler error went away, but the same exact exception was thrown when running the roslyn-based tests

I THINK this is an MSBuild issue... just strange that upgrading to VS 2017 v15.8.2 would cause this type of failure.

rainersigwald commented 5 years ago

That error is usually a result of the machine having (incorrectly) had Microsoft.Build.* assemblies added to the GAC. Can you try running these commands from an administrator developer command prompt?

gacutil /u "MSBuild, Version=15.1.0.0"
gacutil /u "Microsoft.Build.Conversion.Core, Version=15.1.0.0"
gacutil /u "Microsoft.Build, Version=15.1.0.0"
gacutil /u "Microsoft.Build.Engine, Version=15.1.0.0"
gacutil /u "Microsoft.Build.Tasks.Core, Version=15.1.0.0"
gacutil /u "Microsoft.Build.Utilities.Core, Version=15.1.0.0"
gacutil /u "Microsoft.Build.Framework, Version=15.1.0.0"
ghost commented 5 years ago

does that include msbuild 14.x assemblies that were added by VS 2015? We are having this issue and the commands you listed above didnt uninstall anything. VS 2017 version 15.8.28010.2036.

rainersigwald commented 5 years ago

@fifthgearonline MSBuild 14.0 assemblies should be in the GAC if VS 2015 or Build Tools 2015 is installed. What is the exact error you're getting?

jlarbi commented 5 years ago

@rainersigwald Same issue when loading a .csproj using MSBuildWorkspace. It was working when i had only VS2015 installed, but since I installed vs2017, I get this error : -- ERROR: Msbuild failed when processing the file 'D:\DCGF_KillCA\Externals\XRoslyn\MyTypes\MyTypes.csproj' with message: Invalid static method invocation syntax: "[Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries($(TargetFrameworkIdentifier), $(TargetFrameworkVersion), $(TargetFrameworkProfile), $(PlatformTarget), $(TargetFrameworkRootPath), $(TargetFrameworkFallbackSearchPaths))". Méthode 'Microsoft.Build.Utilities.ToolLocationHelper.GetPathToStandardLibraries' introuvable. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(a, b)). C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets

jlarbi commented 5 years ago

Previously, I assume it was doing stuff in C:\Program Files (x86)\Microsoft Visual Studio\2015.... and it was working

jlarbi commented 5 years ago

The code : var lBuildConfiguration = new Dictionary<string, string> { { "Configuration", "Release" }, // Or "Debug", or whatever is known to your projects. { "Platform", "x86" }, // Or x64, AnyCPU, etc... { "CheckForSystemRuntimeDependency", "true" } // ... more properties that could influence your property, };

        this.mWork = MSBuildWorkspace.Create( lBuildConfiguration );
        this.mWork.LoadMetadataForReferencedProjects = true;
        this.mWork.SkipUnrecognizedProjects = false;
        // Load the project straight.
         this.mProject = this.mWork.OpenProjectAsync( pProjectPath ).Result;

Can we force a MSbuild version in config strings?

jlarbi commented 5 years ago

I suspecte when trying to load a csproj (inducing there is no solution at open time) MSbuildWorkspace create a default one to load my csproj in it. In the case there was only VS2015, the default solution created was VS2015, but now there is vs2017, the default solution MSbuildWorkspace is creating is a VS2017 temp sln which attempt to load a csproj vs2015 formatted that obviously mismatches in matter of (MSBuildExtensionsPath)\$(MSBuildToolsVersion) or whatever...

Chetic commented 5 years ago

I started getting this exact issue after a visual studio upgrade. ~~Does it make a difference that I am relying on this workaround? (from https://github.com/Microsoft/msbuild/issues/2369): Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe");~~

Oh and I do not get any 15.x versions listed when executing gacutil /l Microsoft.Build

Edit: Upgraded Microsoft.Build to 15.9.20 and Microsoft.CodeAnalysis to 2.10.0 and no longer need workaround. Issue remains.

syszone commented 5 years ago

That error is usually a result of the machine having (incorrectly) had Microsoft.Build.* assemblies added to the GAC. Can you try running these commands from an administrator developer command prompt?

gacutil /u "MSBuild, Version=15.1.0.0"
gacutil /u "Microsoft.Build.Conversion.Core, Version=15.1.0.0"
gacutil /u "Microsoft.Build, Version=15.1.0.0"
gacutil /u "Microsoft.Build.Engine, Version=15.1.0.0"
gacutil /u "Microsoft.Build.Tasks.Core, Version=15.1.0.0"
gacutil /u "Microsoft.Build.Utilities.Core, Version=15.1.0.0"
gacutil /u "Microsoft.Build.Framework, Version=15.1.0.0"

Amazing this works for me, I have had upgraded VS2017 to 15.9.12 and started having an issue with error Method not found: 'Int32 Microsoft.Build.Execution.ProjectInstance.get_EvaluationId()'.

Thanks