Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#380 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
csharp
Ambito
build-system

Direzione di ricerca

Iniziare con MSBuildLocator.RegisterMSBuildPath e il percorso di caricamento dei progetti di Microsoft.Build.Evaluation, quindi confrontare il modo in cui MSBuild dalla riga di comando risolve le voci msbuild-sdks in global.json. Il lavoro è completo quando si è determinato se gli SDK personalizzati, come Microsoft.Build.NoTargets, possono essere risolti all'interno del processo e si è documentato o riprodotto il comportamento supportato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
C#
Stelle
262
Fork
91
Merge medio
11g 22h
PR unite (30g)
3

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/MSBuildLocator

Tutte le issue di microsoft/MSBuildLocator

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.