So I want to do some things which require inspecting my solution files and projects. Roslyn seems like the way to go - so I find some sample code:
MSBuildLocator.RegisterDefaults();
var workspace = MSBuildWorkspace.Create();
var sln = await workspace.OpenSolutionAsync(solutionPath);
put the following in csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="7.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.7.0" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.4.1" />
</ItemGroup>
and press run - it builds fine - and then doesn't work at all -
Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp.Workspaces, Version=4.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified
and google as I might, I can't find a solution to it - I found something that said yeah, just add the msbuild locator, which did nothing.
Any ideas how I fix this?
I sort of got it working by
and oddly enough it works - but in another thread - it's throwing an unhandled exception