How to use MSBuildWorkspace in Roslyn to analyse C# projects in .NET Interactive? #2624
roberthusak
started this conversation in
General
Replies: 2 comments
-
I solved it by installing Microsoft.Build.Framework.dll version 17.1. |
Beta Was this translation helpful? Give feedback.
0 replies
-
We pull in a specific version of Roslyn to provide C# language support, so as it was mentioned above, you'll need to pull in any additional packages necessary to load/analyze the project, like MSBuild. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The package and version I'm asking about:
Version: 1.0.317502+9c2a225c543085a04516cc4fc490919d5925ba87
Build date: 2022-04-20T11:12:26.5754202Z
https://github.com/dotnet/interactive
Question
Hi, I'd like to use Microsoft Roslyn to analyse an existing C# project from a Jupyter notebook in VS Code, mainly to explore and visualise the code base. What is the best way to use Roslyn in .NET Interactive so that I don't stumble upon problems with wrongly loaded assemblies etc.?
I'm trying to load the project using the
MSBuildWorkspace
so that all the source files and references are loaded by MSBuild. To properly initialize MSBuild,MSBuildLocator
is used:However, I'm currently getting the following exception:
By attaching to the process and inspecting loaded assemblies via VS, I found that .NET Interactive is distributed with its own assembly
Microsoft.Build.Framework.dll
, which is loaded instead of the one located in the SDK folder (Microsoft.Build.dll
is thanks toMSBuildLocator
correctly loaded from the SDK folder):The type
Microsoft.Build.Framework.Traits
is missing in the assembly distributed with .NET Interactive, hence the exception.I wasn't able to force the runtime to load
Microsoft.Build.Framework.dll
from the SDK folder (AssemblyLoadContext.Default.LoadFromAssemblyPath
etc.) instead of the one distributed with .NET Interactive. However, even if I succeeded, it doesn't even seem to me as the correct way to solve this, as it may cause other problems along the way. Do you have any suggestions how to approach this problem? And, maybe, how to approach assembly name collisions in .NET Interactive in general?I might end up running MSBuild in the separate process and then creating the Roslyn
Compilation
object in the notebook manually (apart from the MSBuild stuff, Roslyn seems to work in notebooks), but I'd like to do it in a cleaner way, if there is any.Thanks a lot in advance,
Robert
Beta Was this translation helpful? Give feedback.
All reactions