Fix findGlobalJsonFile boundary check for custom checkout paths (#21989)#22001
Open
rishabhmalikMS wants to merge 7 commits intomasterfrom
Open
Fix findGlobalJsonFile boundary check for custom checkout paths (#21989)#22001rishabhmalikMS wants to merge 7 commits intomasterfrom
rishabhmalikMS wants to merge 7 commits intomasterfrom
Conversation
When workingDirectory resolves outside Build.SourcesDirectory (e.g. multi-repo checkout with custom path), findGlobalJsonFile() returned null, causing MTP detection to fail and the --solution flag to be omitted for .slnx files. Add a fallback chain for the search boundary: 1. Build.SourcesDirectory (default) 2. System.DefaultWorkingDirectory (covers single-checkout with custom path) 3. Agent.BuildDirectory (covers multi-repo checkout) Added unit test for the multi-repo checkout scenario.
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
1 similar comment
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
When workingDirectory resolves outside Build.SourcesDirectory (e.g. multi-repo checkout with custom path), findGlobalJsonFile() returned null, causing MTP detection to fail and the --solution flag to be omitted for .slnx files. Add a fallback chain for the search boundary: 1. Build.SourcesDirectory (default) 2. System.DefaultWorkingDirectory (covers single-checkout with custom path) 3. Agent.BuildDirectory (covers multi-repo checkout) Added unit test for the multi-repo checkout scenario.
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
1 similar comment
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
…ub.com/microsoft/azure-pipelines-tasks into users/rishabhmalikMS/fix_dotnetcorecli
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
1 similar comment
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
1 similar comment
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
dassayantan24
suggested changes
Apr 23, 2026
| @@ -147,7 +147,7 @@ export class dotNetExe { | |||
| } | |||
|
|
|||
| private findGlobalJsonFile(): string | null { | |||
Contributor
There was a problem hiding this comment.
I think we can have single reporoot and no fallback
private findGlobalJsonFile(): string | null {
const boundary = path.resolve(
tl.getVariable('Agent.BuildDirectory') || process.cwd()
);
let searchDir = path.resolve(this.workingDirectory || process.cwd());
while (true) {
const candidate = path.join(searchDir, 'global.json');
if (tl.exist(candidate)) return candidate;
const parentDir = path.dirname(searchDir);
if (parentDir === searchDir) break;
const rel = path.relative(boundary, parentDir);
if (rel.startsWith('..') || path.isAbsolute(rel)) break;
searchDir = parentDir;
}
return null;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Fixes #21989
Regression introduced in v2.271 by PR #21892 ("fix global.json lookup at repository root"). Users running
dotnet testwithMicrosoft Testing Platform (MTP) and
.slnxfiles get failures when using custom checkout paths (e.g.,checkout: selfwithpath:in multi-repo pipelines).
Task Name
DotNetCoreCLIV2
Description
findGlobalJsonFile()usesBuild.SourcesDirectoryas the upper boundary when walking up fromworkingDirectoryto findglobal.json. With custom checkout paths (multi-repo checkout orcheckout: selfwithpath:),workingDirectorycan resolveoutside
Build.SourcesDirectory, causing the function to returnnull. This makes MTP detection fail, so the--solutionflag isnot added to
dotnet test, which newer .NET SDKs require for MTP projects.Fix: Add a fallback chain for the search boundary:
Build.SourcesDirectory(default — works for standard checkout)System.DefaultWorkingDirectory(covers single-checkout with custom path)Agent.BuildDirectory(covers multi-repo checkout where both above stay at/s)Risk Assessment (Low)
workingDirectoryis already outsideBuild.SourcesDirectory(currently broken — returnsnull). No change to existing working scenarios.Change Behind Feature Flag (No)
This is a bug fix for a regression. The current behavior (returning
nullwhen workingDirectory is outside SourcesDirectory) isalways wrong — there is no scenario where the broken behavior is desirable. A feature flag would leave affected users broken.
Tech Design / Approach
findGlobalJsonFile()boundary check now tries three well-known pipeline variables in order:Build.SourcesDirectory→System.DefaultWorkingDirectory→Agent.BuildDirectoryAgent.BuildDirectoryis the tightest safe boundary that covers all possible checkout locationsDocumentation Changes Required (No)
No user-facing documentation changes needed. The fix restores expected behavior.
Unit Tests Added or Updated (Yes)
runTestsWithWorkingDirOutsideSourcesDir.ts— simulates the exact multi-repo checkout scenario from issue [BUG]: Solution Flag "--solution" is missing in DotNetCoreCLI #21989with
Build.SourcesDirectory,System.DefaultWorkingDirectory, andAgent.BuildDirectoryall set to different valuesL0.ts— added test case verifyingAgent.BuildDirectoryfallback is used,global.jsonis found, and--solutionflag is added
Additional Testing Performed
checkout: selfwithpath: repository+ second repo) on Azure DevOps hosted agent:global.json not found, no--solutionflagAgent.BuildDirectoryfallback used,global.jsonfound,--solutionaddedLogging Added/Updated (Yes)
tl.debug()consistent with existing loggingTelemetry Added/Updated (No)
No new telemetry needed — this is a boundary check fix in an existing function.
Rollback Scenario and Process (Yes)
Rollback: revert this commit. The change is isolated to
findGlobalJsonFile()indotnetcore.ts. Version bump to 2.273.0 allowspinning to previous version if needed.
Dependency Impact Assessed and Regression Tested (Yes)
dotnetcore.tsmodified (task logic), no changes to shared packagesChecklist