dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.7k stars 3.98k forks source link

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

Open vsfeedback opened 3 months ago

vsfeedback commented 3 months ago

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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. d__24.MoveNext()<—


Original Comments

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

(private comment, text removed)


Original Solutions

(no solutions)

falpizar commented 3 months ago

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;
CyrusNajmabadi commented 3 months ago

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

     -- Cyrus
JoeRobich commented 3 months ago

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

Metalaka commented 2 months ago

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

tshaug commented 2 months ago

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

Metalaka commented 1 month ago

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

erchauvet commented 1 month ago

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();

_roslynSolution = WSworkspace.CurrentSolution;

en esperant que cela puisse vous débloquer aussi

Cdt Eric

tshaug commented 4 weeks ago

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

jasonmalinowski commented 3 weeks ago

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.