-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix global.json lookup at repository root #21709
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
base: master
Are you sure you want to change the base?
fix global.json lookup at repository root #21709
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| const dotnet = tl.tool(dotnetPath); | ||
| dotnet.arg(this.command); | ||
|
|
||
| if (isMTP && projectFile.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WHy is MTP check being removed ?
| } | ||
|
|
||
| const rel = path.relative(repoRoot, parentDir); | ||
| if (rel.startsWith('..') || path.isAbsolute(rel) && rel === '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rel.startswith("..") does this check works for all os(windows, linux, mac-os?)
| dotnet.arg(this.command); | ||
|
|
||
| if (isMTP && projectFile.length > 0) { | ||
| // https://github.com/dotnet/sdk/blob/cbb8f75623c4357919418d34c53218ca9b57358c/src/Cli/dotnet/Commands/Test/CliConstants.cs#L34 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this block removed?
Context
The DotNetCoreCLI@2 task previously assumed global.json was located in the repository root or current process directory by using a hardcoded check (if (!tl.exist("global.json"))). This approach ignored the task’s workingDirectory input and did not follow official .NET SDK behavior, which searches for global.json in the current working directory or its ancestor directories.
This caused failures in monorepos where multiple .NET projects coexist and global.json is placed in project-specific folders instead of the repo root. .
📌 [Bug 2340658: DotNetCoreCLI@2 global.json lookup is hardcoded to repository root](https://mseng.visualstudio.com/AzureDevOps/_workitems/edit/2340658/?view=edit)
Related Issue - #21523
Task Name
DotNetCoreCLIV2
Description
Implemented findGlobalJsonFile() to:
Start searching from the task’s workingDirectory (or process CWD if not provided).
Walk up ancestor directories until reaching the repo root (Build.SourcesDirectory or System.DefaultWorkingDirectory).
Stop when outside the repo root or filesystem root.
Updated getIsMicrosoftTestingPlatform() to:
Use the new search logic.
Parse global.json using JSON5 for flexible syntax.
Safely extract test.runner property and log detection result.
while Fixing the global.json issue one more issue is found -
dotnet test failed with errors like MSB1001: Unknown switch --project/--solution after global.json–based SDK detection was added. This occurred because the task started passing --project / --solution flags when invoking dotnet test.
Fix
Updated the task to always pass the project/solution as a positional argument for dotnet test, instead of using --project or --solution.
Why
Although dotnet test documents these switches, execution can still fall back to MSBuild in some scenarios (including SDK selection via global.json). MSBuild does not recognize --project or --solution, causing failures. Passing the project/solution positionally is supported by both MTP and MSBuild paths.
Risk Assessment (Low / Medium / High)
Low
Change Behind Feature Flag (Yes / No)
no
Unit Tests Added or Updated (Yes / No)
Added L0 tests.
Additional Testing Performed
Tested MAnually by uploading task to private org - https://dev.azure.com/v-dmerugu0683/Sample%20Project/_build/results?buildId=1137&view=results

Rollback Scenario and Process (Yes/No)
Checklist