Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 428
mortenma71 Avatar asked Dec 06 '17 09:12

mortenma71


2 Answers

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

like image 108
Yuriy Oleynik Avatar answered Oct 22 '22 21:10

Yuriy Oleynik


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.

like image 43
nik Avatar answered Oct 22 '22 22:10

nik