roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

VS 2022 can't find .NET Framework build host after update

Open vsfeedback opened this issue 1 year ago • 12 comments

This issue has been moved from a ticket on Developer Community.


[severity:It’s more difficult to complete my work]
I have an exception in VS 2022 after fresh update from 17.7.1 to 17.9.2. The exception is thrown in my VS add-on by execute following code

var service = (DTE2) Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE));
using (var workspace = MSBuildWorkspace.Create())
{
    var solution = workspace. OpenSolutionAsync(service. Solution.FileName). Result;

}

System.AggregateException: One or more errors occurred. —> System.InvalidOperationException: Unable to locate the .NET Framework build host at c:\program files\microsoft visual studio\2022\enterprise\common7\ide\commonextensions\microsoft\vbcsharp\languageservices\BuildHost-net472\Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.exe - line 206
at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber)
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager.GetPathToDotNetFrameworkBuildHost()
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager.CreateDotNetFrameworkBuildHostStartInfo()
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager. <GetBuildHostAsync>d__8.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager. <GetBuildHostAsync>d__7.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker. <LoadProjectFileInfosAsync>d__20.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker. <LoadProjectInfosFromPathAsync>d__21.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker. <LoadAsync>d__19.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader. <LoadSolutionInfoAsync>d__22.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader. <LoadSolutionInfoAsync>d__22.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace. <OpenSolutionAsync>d__24.MoveNext()
— End of inner exception stack trace —
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at CallsLogger.ExceptionWrapper.ChangeSources(AsyncPackage package, Func3 action)
—> (Inner Exception #0) System.InvalidOperationException: Unable to locate the .NET Framework build host at c:\program files\microsoft visual studio\2022\enterprise\common7\ide\commonextensions\microsoft\vbcsharp\languageservices\BuildHost-net472\Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.exe - line 206
at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber)
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager.GetPathToDotNetFrameworkBuildHost()
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager.CreateDotNetFrameworkBuildHostStartInfo()
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager. <GetBuildHostAsync>d__8.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager. <GetBuildHostAsync>d__7.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker. <LoadProjectFileInfosAsync>d__20.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker. <LoadProjectInfosFromPathAsync>d__21.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker. <LoadAsync>d__19.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader. <LoadSolutionInfoAsync>d__22.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader. <LoadSolutionInfoAsync>d__22.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace. <OpenSolutionAsync>d__24.MoveNext()<—


Original Comments

Feedback Bot on 3/4/2024, 09:19 PM:

(private comment, text removed)


Original Solutions

(no solutions)

vsfeedback avatar Mar 08 '24 15:03 vsfeedback

Found same issue after upgrade. Also needed to process .net 7 projects but fails:

File: MSBuildProjectLoader.cs Class: Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.worker Method: LoadProjectFileInfosAsync

'buildHost' gets null value:

RemoteBuildHost buildHost = (await _buildHostProcessManager.GetBuildHostAsync(projectPath2, cancellationToken..)).Item1;

falpizar avatar Mar 08 '24 20:03 falpizar

@JoeRobich do you have any ideas here while @jasonmalinowski is oof?

     -- Cyrus

CyrusNajmabadi avatar Mar 14 '24 19:03 CyrusNajmabadi

TIL I learned we shipped Workspaces.MSBuild in VS. Seems like a setup authoring issue with the managed languages VS component. We are only shipping one version of the BuildHost and in the wrong folder.

Image

JoeRobich avatar Mar 14 '24 20:03 JoeRobich

Hi, any news on this issue ? extensions on VS 17.9 and 17.10 preview are unable to use MSBuildWorkspace

Metalaka avatar Apr 08 '24 13:04 Metalaka

Hi everybody,

is there any workaround available to mitigate this issue (e.g. copying required exe and ddls into the "right" directory"?). At the moment I am stuck. Thank you very much! Thomas

tshaug avatar Apr 17 '24 09:04 tshaug

Hello @CyrusNajmabadi, it seems that the contentFiles added in Microsoft.CodeAnalysis.Workspaces.MSBuild v4.9 by https://github.com/dotnet/roslyn/pull/70469 is not correctly shipped by the VS installer.

The nuget Microsoft.CodeAnalysis.Workspaces.MSBuild @ 4.9.0-3.final is deployed in C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\VBCSharp\LanguageServices but the contentFiles is missing. If I manually copy the folder BuildHost-net472 and BuildHost-netcore from the nuget to the VS installation folder my extension works fine.

Can anyone investigate why the contentFiles is missing or maybe transfert the issue to the VS team ? Thanks

Metalaka avatar May 16 '24 19:05 Metalaka

Bonjour je rencontrais le même problème que vous avec vs2022 (17.10.1) mon ancien code _solution.GetSolutionInfo(out string solutionDirectory, out string solutionFile, out string solutionOptions);

/* using (var workspace = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create()) { JoinableTaskFactory.Run(async delegate { _roslynSolution = await workspace.OpenSolutionAsync(solutionFile); }); } */

mon nouveau code var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)); var WSworkspace = componentModel.GetService<Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace>();

_roslynSolution = WSworkspace.CurrentSolution;

en esperant que cela puisse vous débloquer aussi

Cdt Eric

erchauvet avatar May 30 '24 16:05 erchauvet

@erchauvet Thanks for providing your code snippet. It solves my problem :-)

tshaug avatar Jun 04 '24 19:06 tshaug

So for folks who are trying to use MSBuildWorkspace to analyze the currently open solution -- you should not be using MSBuildWorkspace in that situation -- @erchauvet's code snippet is what you should be doing the VisualStudioWorkspace represents the current open solution, and will be vastly faster to use, since that's the same snapshot we're driving many features with.

If you're using it to analyze some other solution, then we'll still get this fixed, but this hopefully gets you in the right direction in a lot of cases.

jasonmalinowski avatar Jun 05 '24 00:06 jasonmalinowski

Same problem

risperdal avatar Aug 19 '24 10:08 risperdal

Same problem

testirme avatar Aug 19 '24 10:08 testirme

I guess the problem is related to updated version of Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace package. If i downgrade that package to 4.7.0 it still works

risperdal avatar Aug 19 '24 12:08 risperdal

This issue is a critical issue blocking my customers. Will the solution be provided before the official .NET 9 release?

tobyash86 avatar Nov 08 '24 09:11 tobyash86

Same here. See https://github.com/postsharp/PostSharp.Engineering/blob/63aae72db118c43a2d7bdd56f0f093f2ce3b8bad/src/PostSharp.Engineering.BuildTools/XmlDoc/RemoveInternalsCommand.cs#L26

prochan2 avatar Nov 22 '24 07:11 prochan2

This is a problem for us after upgrading to Visual Studio 17.12.2. The workarounds have not been helpful since our program loads other standalone projects for analysis. Please fix!

cirrusqm avatar Dec 03 '24 04:12 cirrusqm

Is anything happening around this issue? All tools that use Roslyn outside of Visual Studio are blocked. Is there any official Microsoft statement about it?

tobyash86 avatar Jan 08 '25 11:01 tobyash86

Fix is merged for 17.14 and 17.13; it's not in 17.13 Preview 3 (which shipped today), but expecting it to be in Preview 4.

jasonmalinowski avatar Jan 22 '25 23:01 jasonmalinowski