Trying to load a project with Sdk.WindowDesktop fails.

Open
#120 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
build-system

Research direction

Start with Microsoft.Build.Evaluation.Project and Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults(), comparing the selected MSBuildPath under Net472 and NetCoreApp31. Reproduce the MSB4236 failure with Microsoft.NET.Sdk.WindowsDesktop and determine what allows the NetCoreApp host to load the SDK project successfully.

Written by the indexing model from the issue text.

Description

I've been trying to load a csproj using new Microsoft.Build.Evaluation.Project("project.csproj", null, null"); and it throws this exception:

The specified SDK "Microsoft.NET.Sdk.WindowsDesktop" could not be found.
Source: Microsoft.Build
Error: MSB4236
MSBuild.CouldNotResolveSdk

The loaded csproj looks like this:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <TargetFramework>net471</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

</Project>

And the host application registers the MSBuild location with:

Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults();

I've noticed different behavior depending on whether the host application is compiled against Net472 or against NetCoreApp31:

On Net472

  • The Microsoft.NET.Sdk.WindowsDesktop projects succeeds to load.
  • MSBuildPath of Locator Instance points to: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin"

On NetCoreApp3.1

  • The Microsoft.NET.Sdk.WindowsDesktop projects throw an exception on load.
  • MSBuildPath of Locator instance points to: "C:\Program Files\dotnet\sdk\2.2.300"
    On Net4xx:

So I believe this is the reason because it works on Net4 and not on NetCore.

Is there a way to solve this issue and make the "Microsoft.NET.Sdk.WindowsDesktop" projects to load while the host app is NetCoreApp?

Dominant language
C#
Stars
262
Forks
91
Avg merge
11d 22h
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/MSBuildLocator

All issues in microsoft/MSBuildLocator

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.