'Can not get Roslyn to work with .NET 5 project
After spending way too much time, I still can't make Roslyn to load simple C# project. Project source:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="16.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="3.11.0" />
</ItemGroup>
</Project>
Code that is trying to load:
using System;
using Microsoft.CodeAnalysis.MSBuild;
namespace Metrics5
{
class Program
{
static void Main(string[] args)
{
using var workspace = MSBuildWorkspace.Create();
workspace.LoadMetadataForReferencedProjects = true;
var currentProject = workspace.OpenProjectAsync(@"C:\work\Metrics5\Metrics5.csproj").Result;
var diagnostics = workspace.Diagnostics;
foreach(var diagnostic in diagnostics)
{
Console.WriteLine(diagnostic.Message);
}
}
}
}
It says:
Msbuild failed when processing the file 'C:\work\Metrics5\Metrics5.csproj' with message: The SDK 'Microsoft.NET.Sdk' specified could not be found. C:\work\Metrics5\Metrics5.csproj
After I add MSBuildSDKsPath as environment value MSBuildSDKsPath=C:\Program Files\dotnet\sdk\5.0.301\Sdks it seems to pass that step and stuck in another:
Msbuild failed when processing the file 'C:\work\Metrics5\Metrics5.csproj' with message: The imported project "C:\work\Metrics5\bin\Debug\net5.0\Current\Microsoft.Common.props" was not found. Confirm that the expression in the Import de claration "C:\work\Metrics5\bin\Debug\net5.0\Current\Microsoft.Common.props" is correct, and that the file exists on disk. C:\Program Files\dotnet\sdk\5.0.301\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props
And from here I'm not sure how to proceed, am I missing some nuget package? Do I need to install additionally something?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
