load inline task code file relatively to project instead of CWD - #12687
#12687Merged
JanProvaznik merged 7 commits intoNov 18, 2025
dotnet:maindotnet/msbuild:mainfrom
JanProvaznik:mt-factories-pathsJanProvaznik/msbuild:mt-factories-pathsCopy head branch name to clipboard
Merged
load inline task code file relatively to project instead of CWD#12687JanProvaznik merged 7 commits intodotnet:maindotnet/msbuild:mainfrom JanProvaznik:mt-factories-pathsJanProvaznik/msbuild:mt-factories-pathsCopy head branch name to clipboard
JanProvaznik merged 7 commits into
dotnet:maindotnet/msbuild:mainfrom
JanProvaznik:mt-factories-pathsJanProvaznik/msbuild:mt-factories-pathsCopy head branch name to clipboard
Conversation
…an cwd in mt mode, add test
Contributor
There was a problem hiding this comment.
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
RoslynCodeTaskFactoryandCodeTaskFactoryto 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 |
…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
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
|
validated it resolves the problem for MSBuild-building-MSBuild with -mt on the commit from the original issue. |
SimaTian
reviewed
Nov 8, 2025
SimaTian
approved these changes
Nov 8, 2025
This was referenced Nov 19, 2025
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.
Fixes #12680
Context
When code file for
RoslynCodeTaskFactory/CodeTaskFactoryis 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