Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

load inline task code file relatively to project instead of CWD - #12687

#12687
Merged
JanProvaznik merged 7 commits into
dotnet:maindotnet/msbuild:mainfrom
JanProvaznik:mt-factories-pathsJanProvaznik/msbuild:mt-factories-pathsCopy head branch name to clipboard
Nov 18, 2025
Merged

load inline task code file relatively to project instead of CWD#12687
JanProvaznik merged 7 commits into
dotnet:maindotnet/msbuild:mainfrom
JanProvaznik:mt-factories-pathsJanProvaznik/msbuild:mt-factories-pathsCopy head branch name to clipboard

Conversation

@JanProvaznik

Copy link
Copy Markdown
Member

Fixes #12680

Context

When code file for RoslynCodeTaskFactory/CodeTaskFactory is specified, it is fetched relative to cwd which in multiprocess is equal to project directory but in multithreaded this is no longer the case.

Changes Made

Get Project path from buildengine in taskfactory initialization

change only in mt mode to align mt behavior with multiproc

Testing

integration and unit test

Notes

Copilot AI review requested due to automatic review settings October 21, 2025 11:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where inline task code files with relative paths fail to resolve correctly in multithreaded builds. In multiprocess builds, relative paths work because the current working directory matches the project directory, but in multithreaded mode this is no longer true.

Key Changes:

  • Added path resolution logic that resolves relative code file paths against the project directory instead of CWD in multithreaded mode
  • Modified both RoslynCodeTaskFactory and CodeTaskFactory to use the new resolution logic
  • Added comprehensive integration and unit tests to verify the fix

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/UnitTests.Shared/MockEngine.cs Changed ProjectFileOfTaskNode from read-only to settable property to support test scenarios
src/Tasks/RoslynCodeTaskFactory/RoslynCodeTaskFactory.cs Added project-relative path resolution for code source files in multithreaded builds
src/Tasks/CodeTaskFactory.cs Added project-relative path resolution for code source files in multithreaded builds
src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs Added integration test with multi-project solution and unit test for path resolution logic
src/Shared/TaskFactoryUtilities.cs Added ResolveTaskSourceCodePath utility method to handle path resolution logic

Comment thread src/Tasks/RoslynCodeTaskFactory/RoslynCodeTaskFactory.cs
Comment thread src/Tasks/CodeTaskFactory.cs Outdated
Comment thread src/Shared/TaskFactoryUtilities.cs Outdated
…tform paths

- Guard against empty ProjectFileOfTaskNode by checking before Path.GetDirectoryName
- Use Path.Combine for cross-platform path separators in test
- Fixes ArgumentException on empty path and FileNotFoundException on Linux
@JanProvaznik

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@JanProvaznik

Copy link
Copy Markdown
Member Author

validated it resolves the problem for MSBuild-building-MSBuild with -mt on the commit from the original issue.

Comment thread src/Shared/TaskFactoryUtilities.cs Outdated
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.

Multithreaded inline task factories should work with relative paths to code files

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.