`MSBuildLocator.RegisterMSBuildPath()` not registering custom SDKs configured through `msbuild-sdks` in `globals.json`

Open
#380 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start with MSBuildLocator.RegisterMSBuildPath and the Microsoft.Build.Evaluation project-loading path, then compare how command-line MSBuild resolves the msbuild-sdks entries in global.json. Done means determining whether custom SDKs such as Microsoft.Build.NoTargets can be resolved in-process and documenting or reproducing the supported behavior.

Written by the indexing model from the issue text.

Description

I'm working in a code repository which configures several of the custom project SDK types provided by the MSBuildSdks repo, which are configured in the root global.json file of that repo:

{
    "msbuild-sdks":
	{
      "Microsoft.Build.Traversal": "4.1.82",
      "Microsoft.Build.NoTargets": "3.7.134"
    }
}

In building a tool that uses the Microsoft.Build.Evaluation library to scan the projects in this repo, I am so far unable to get the in-process library to register these custom project types. When attempting to load a project that either uses one of these custom SDK types or which references another project via a <ProjectReference> which in turn uses one, it fails with an exception like the one below:

Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.Build.NoTargets' specified could not be found.  NoTargets.proj
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1](IElementLocation elementLocation, String resourceName, T1 arg0)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, SdkResult& sdkResult)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate()
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ICollection`1 propertiesFromCommandLine, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, IDirectoryCacheFactory directoryCacheFactory, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, Boolean interactive)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, IDirectoryCacheFactory directoryCacheFactory, Boolean interactive)

Building these projects that use the NoTargets SDK from the command line succeeds, so the command line MSBuild tool seems to be finding these custom project SDK types. And in other ways, the in-process Microsoft.Build.Evaluation library appears to be configured correctly as all other projects that don't reference these SDK types load just fine.

Is this a scenario that the MSBuildLocator supports? Is it possible to get the in-memory libraries to locate and use these custom SDKs when evaluating projects?

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.