Skip to content

Conversation

@v-dmerugu
Copy link
Contributor

@v-dmerugu v-dmerugu commented Jan 18, 2026

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
image

image

Rollback Scenario and Process (Yes/No)

  • Rollback plan is documented.

Checklist

  • Related issue linked (if applicable)
  • Task version was bumped — see versioning guide
  • Verified the task behaves as expected

@v-dmerugu
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@v-dmerugu
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

const dotnet = tl.tool(dotnetPath);
dotnet.arg(this.command);

if (isMTP && projectFile.length > 0) {
Copy link
Collaborator

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 === '') {
Copy link
Contributor

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
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants