-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The SDK 'Microsoft.NET.Sdk' specified could not be found. #58286
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Any update and/or workaround for this? |
|
The same problem met |
I'm also able to reproduce. csproj file: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Locator" Version="1.5.3" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.2.0" />
</ItemGroup>
</Project>
Program.cs: using System.Reflection;
using Microsoft.Build.Locator;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
internal class Program {
public static async Task Main(string[] args) {
var vs = MSBuildLocator.QueryVisualStudioInstances().First();
Console.WriteLine(vs.Name);
Console.WriteLine(vs.Version);
Console.WriteLine(vs.DiscoveryType);
Console.WriteLine(vs.MSBuildPath);
Console.WriteLine(vs.VisualStudioRootPath);
Console.WriteLine();
MSBuildLocator.RegisterDefaults();
using (var workspace = MSBuildWorkspace.Create()) {
workspace.WorkspaceFailed += Workspace_WorkspaceFailed;
var project = await workspace.OpenProjectAsync(@"/path/to/file.csproj");
}
}
private static void Workspace_WorkspaceFailed(object? sender, WorkspaceDiagnosticEventArgs e) {
Console.WriteLine(e.Diagnostic.Message);
}
} Prints:
SDKs installed:
VS versions installed: 2019, 2022, 2022-preview |
@LordBenjamin Your original code would work if you downgrade MSBuildLocator to version 1.4.1. Seems that something has regressed in that package. |
@yiszza To use MSBuildWorkspace we recommend using MSBuildLocator to load an installation of MSBuild Tools either from a .NET SDK or a VS install. In your project you only referenced the |
Thanks @JoeRobich, downgrading to 1.4.1 works for me and saves my day. It's the bug correctly tracked here? |
The bug is microsoft/MSBuildLocator#176. One workaround is to query for the instance your want then when registering the MSBuildPath, ensure it ends with a directory separator. var instance = MSBuildLocator.QueryVisualStudioInstances().First();
var msBuildPath = Path.EndsInDirectorySeparator(instance.MSBuildPath)
? instance.MSBuildPath
: instance.MSBuildPath + Path.DirectorySeparatorChar;
MSBuildLocator.RegisterMSBuildPath(msBuildPath); |
Version Used: latest version
Steps to Reproduce:
RoslynTest.zip
code :
run the demo,
Expected Behavior: project.Documents.Count() != 0;
Actual Behavior: project.Documents.Count() == 0; The SDK 'Microsoft.NET.Sdk' specified could not be found.
The text was updated successfully, but these errors were encountered: