27
votes

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

6
Came across these threads on github github.com/Microsoft/msbuild/issues/2775, github.com/dotnet/docfx/issues/2265 (however, I can't deduct the pratcial solution from the thread).mortenma71
another related thread github.com/dotnet/docfx/pull/2267mortenma71
FYI I've had VS2017 Enterprise installed side-by-side with VS2017 pro for a long time. Been using pro all the time. All projects load just fine in Enterprise (with ReSharper installed and doing the builds). It appears only my VS2017 pro 15.5 installation is broken.mortenma71
Really appreciate your sharing. And I noticed that you are solving this issue with product group, if there is any conclusion and workaround, you can share it here. It is benefit to other communities who has the same problem.Leo Liu-MSFT
I am also facing the same problem after updating VS 2017 to v15.6.5. Have you found any solution or workaround to sort it out?Selvamz

6 Answers

25
votes

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

0
votes

The solution, provided by henkmollema in this thread: https://github.com/Microsoft/msbuild/issues/2775 was to start the visual studio installer from the start menu and run a repair.

enter image description here

0
votes

After installing the latest Visual Studio Version via the Updater, I received the same error messages.

The issue was resolved, at least in my case, by rebooting after installing the Visual Studio update.

0
votes

I had this problem with Visual Studio 2017 on a Windows 7 PC on a corporate network. I tried to fix the issue in the following ways:

  • restarting the computer/Visual Studio several times (as mentioned by an answer here).
  • upgrading to the newest version of Visual Studio found in "Extensions and Updates"
  • Using the "Repair" option in the installer.
  • Uninstalling it completely by uninstalling the "Visual Studio Installer" (Control Panel → Add remove programs), and then re-installing it.

I noticed that on a colleague's computer, which never had VS2017 installed, when I installed VS2017 Community Edition version 15.5, there was no issue.

At this point, I have to admit defeat. The only simple solution is to replace the line in the file:

  • C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets

There is a line near the end of the file:

<NuGetRestoreTargets Condition="'$(NuGetRestoreTargets)'=='' and '$([MSBuild]::IsRunningFromVisualStudio())'=='true'">$(MSBuildToolsPath32)\..\..\..\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets</NuGetRestoreTargets>

just replace the $([MSBuild]::IsRunningFromVisualStudio()) with true:

<NuGetRestoreTargets Condition="'$(NuGetRestoreTargets)'=='' and 'true'=='true'">$(MSBuildToolsPath32)\..\..\..\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets</NuGetRestoreTargets>

however this only allows the projects to load up - you cannot use it to build the project.

I am going to ask for my machine to be re-imaged so I can just download and install Visual Studio from scratch.

(I hope Microsoft come up with a fix soon.)

0
votes

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.

0
votes

Besides the assemblies mentioned in Yuriy Oleynik's answer, I found I need to add an additional assembly (see the last command below) in gac (I'm using VS 2019):

gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.Conversion.Core.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.Engine.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.Framework.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.Tasks.Core.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.Utilities.Core.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\System.Collections.Immutable.dll"