Invalid static method invocation syntax: "[MSBuild]::IsRunningFromVisualStudio()"

15,151

Solution 1

1. Close all running instances of Visual Studio 2017

2. Launch (as Administrator) "Developer Command Prompt for VS 2017"

3. Type the following commands (replace Professional with your edition, either Enterprise or Community, or adjust the path accordingly):

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Framework.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Engine.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Conversion.Core.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Tasks.Core.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Utilities.Core.dll"

4. Restart Visual Studio 2017

Solution 2

It seems from the responses to this issue on github that it is often caused by having an older version of MSBuild in the GAC. This will then be used in preference to the bundled version that ships with the updated version of VS.

The solution is to remove the old version of Microsoft.Build from the gac.

  1. Find the gac'd versions:

    gacutil /l | findstr Microsoft.Build

  2. Look for any of version 15.x.x.x and then remove them:

    gacutil /u "Microsoft.Build, Version=15.{version_found}"

  3. Restart Visual Studio

It may also be necessary to remove the related assemblies Microsoft.Build.Utilities.Core, Microsoft.Build.Framework and Microsoft.Build.Tasks.Core of that version.

Share:
15,151

Related videos on Youtube

mortenma71
Author by

mortenma71

Updated on September 14, 2022

Comments

  • mortenma71
    mortenma71 over 1 year

    After upgrading to Visual Studio 2017 15.5 none of my project will load correctly. All are marked unavailable.

    I'm getting the following error for every project:

    error : Invalid static method invocation syntax: "[MSBuild]::IsRunningFromVisualStudio()". Method '[MSBuild]::IsRunningFromVisualStudio' 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\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets

    Reloading project produces this error prompt: enter image description here

    Adding new projects produce this error prompt:

    enter image description here

  • Tahir Hassan
    Tahir Hassan about 6 years
    Not for me either.
  • Ondřej Kunc
    Ondřej Kunc about 6 years
    I ran this commands on my build server and it broke all our builds - specifically it broke vswhere.exe utility, which locates concrete version of MSBuild. Had to fix it by locating all newly added assemblies by gcutil and unistall them using gacutil /u
  • Nick Baker
    Nick Baker over 5 years
    Fixed it for me as well. I had to run this as well: gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\System.Collections‌​.Immutable.dll" as I got Could not load file or assembly 'System.Collections.Immutable blah blah.
  • orellabac
    orellabac over 5 years
    mmm this partially helped. I god rid of this problem but then I got to The SDK Microsoft.NET.Sdk specified could not be found
  • orellabac
    orellabac over 5 years
    After that I had to install Microsoft.CodeAnalysis.Workspaces.MSBuild and also Microsoft.Build.Locator as recommended in stackoverflow.com/questions/49816884/…
  • Rahul Reddy Vemireddy
    Rahul Reddy Vemireddy over 4 years
    This has messed up my Visual Studio. Could you please suggest how to fix it?
  • Yuriy Oleynik
    Yuriy Oleynik over 4 years
    @RahulReddyVemireddy run all commands with flag /u (ex. gacutil /u)
  • alamoot
    alamoot over 3 years
    Fixed my issue.