Skip to content

Migrate CMake.Sdk, Templating, XliffTasks and FileCatalog tasks to multithreaded MSBuild - #17507

Merged
ViktorHofer merged 6 commits into
dotnet:mainfrom
ViktorHofer:mt-safe-subset-3
Sep 8, 2026
Merged

ViktorHofer merged 6 commits into
dotnet:mainfrom
ViktorHofer:mt-safe-subset-3

Conversation

@ViktorHofer

@ViktorHofer ViktorHofer commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Next safe subset of #17381: the CMake.Sdk, Templating, XliffTasks and FileCatalog tasks.

  • Tasks opt into [MSBuildMultiThreadableTask] / IMultiThreadableTask and resolve every path through TaskEnvironment.GetAbsolutePath before touching the filesystem.
  • XlfDocument's racy static XmlSchemaSet becomes a Lazy<T> that compiles the set before publishing it, since XmlSchemaSet mutates itself during validation.
  • Document, CatalogBuilder and CatalogEntry take FileInfo rather than string. The analyzer's transitive check needs a typed path to flow into the file I/O, and FileInfo keeps these model types free of any Microsoft.Build.Framework dependency - same approach as NuGetVersionUpdater in Opt a second set of tasks into multithreaded execution #17497. Task classes stay on AbsolutePath and convert at the call boundary.
  • UpdateXlf compares FileNotFoundException.FileName against the absolute path it passed in, not the original relative one.
  • Restores canonicalization that GetAbsolutePath deliberately omits but Path.GetFullPath performed, wherever the result is compared, emitted as an output property or item metadata, or embedded in a generated file: GetCMakeArtifactsFromFileApi (directory match and artifact item specs), GenerateFileFromTemplate (ResolvedOutputPath), GatherTranslatedSource (DependentUpon) and TranslateSource (paths rewritten into the translated document).
  • Adds an internal GetCanonicalForm() polyfill because that API is not public in the MSBuild packages this repo consumes; tracked for removal by Remove the AbsolutePath.GetCanonicalForm polyfill once Arcade consumes an MSBuild with the public API #17506.

One pre-existing quirk is deliberately left alone: GetCMakeArtifactsFromFileApi only normalizes dirSource when it is not already rooted, so a rooted value is still compared un-normalized. That predates this change and has no CWD dependency.

…ltithreaded MSBuild

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
Copilot AI lite review requested due to automatic review settings September 8, 2026 10:39

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.

Copilot review overview

🔵 Needs a closer look

It changes execution/threading and path-resolution behavior across multiple build task assemblies, which merits a final human review plus full build/test validation.

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​Microsoft.DotNet.XliffTasks/​Model/​XlfDocument.cs — CreateSchemaSet() allocates resource streams and XmlReaders without disposing them. Even though…
What changed in this PR

This PR migrates additional self-contained Arcade task assemblies (CMake.Sdk, Templating, XliffTasks, FileCatalog) to be safe for in-proc multi-threaded MSBuild execution by opting into [MSBuildMultiThreadableTask], implementing IMultiThreadableTask, and resolving paths through TaskEnvironment (with canonicalization restored where outputs/comparisons require it).

Changes:

  • Opt tasks into multi-threaded execution and inject TaskEnvironment for project-relative path/environment resolution.
  • Flow AbsolutePath into task-private helpers/models and reintroduce canonicalization via GetCanonicalForm() where paths are compared/emitted/embedded.
  • Make XLIFF schema validation state thread-safe via Lazy<XmlSchemaSet> and pre-compilation.
File Description
src/​Microsoft.DotNet.XliffTasks/​Tasks/​XlfTask.cs Base task now implements IMultiThreadableTask and uses AbsolutePath for document loading.
src/​Microsoft.DotNet.XliffTasks/​Tasks/​UpdateXlf.cs Uses TaskEnvironment.GetAbsolutePath for file IO and corrects FileNotFoundException.FileName comparison.
src/​Microsoft.DotNet.XliffTasks/​Tasks/​TranslateSource.cs Resolves inputs/outputs via TaskEnvironment and canonicalizes embedded rewritten paths.
src/​Microsoft.DotNet.XliffTasks/​Tasks/​TransformTemplates.cs Resolves copy/load/save paths through TaskEnvironment for thread-safe execution.
src/​Microsoft.DotNet.XliffTasks/​Tasks/​SortXlf.cs Resolves XLF path IO through TaskEnvironment.
src/​Microsoft.DotNet.XliffTasks/​Tasks/​GatherTranslatedSource.cs Canonicalizes emitted DependentUpon metadata using TaskEnvironment + canonical form.
src/​Microsoft.DotNet.XliffTasks/​Tasks/​EnsureAllResourcesTranslated.cs Resolves XLF load paths through TaskEnvironment.
src/​Microsoft.DotNet.XliffTasks/​Model/​XlfDocument.cs Makes schema set initialization thread-safe and compiled before use.
src/​Microsoft.DotNet.XliffTasks/​Model/​Document.cs Switches Load/Save APIs to AbsolutePath to ensure task-boundary path resolution.
src/​Microsoft.DotNet.XliffTasks/​Microsoft.DotNet.XliffTasks.csproj Links in AbsolutePathExtensions polyfill for canonicalization.
src/​Microsoft.DotNet.CMake.Sdk/​src/​GetCMakeArtifactsFromFileApi.cs Task becomes multi-threadable; resolves/canonicalizes paths for comparisons and item specs.
src/​Microsoft.DotNet.CMake.Sdk/​src/​CreateCMakeFileApiQuery.cs Task becomes multi-threadable; resolves filesystem paths via TaskEnvironment.
src/​Microsoft.DotNet.CMake.Sdk/​Microsoft.DotNet.CMake.Sdk.csproj Links in AbsolutePathExtensions polyfill.
src/​Microsoft.DotNet.Build.Tasks.Templating/​src/​Microsoft.DotNet.Build.Tasks.Templating.csproj Links in AbsolutePathExtensions polyfill.
src/​Microsoft.DotNet.Build.Tasks.Templating/​src/​GenerateFileFromTemplate.cs Task becomes multi-threadable; resolves/canonicalizes output and template paths.
src/​Microsoft.DotNet.Build.Tasks.FileCatalog/​GenerateFileCatalog.cs Task becomes multi-threadable; resolves file/catalog output paths via TaskEnvironment.
src/​Microsoft.DotNet.Build.Tasks.FileCatalog/​CatalogEntry.cs Accepts AbsolutePath so file IO uses task-resolved paths.
src/​Microsoft.DotNet.Build.Tasks.FileCatalog/​CatalogBuilder.cs Accepts AbsolutePath for AddFile/WriteTo to propagate resolved paths.
src/​Microsoft.DotNet.Build.Tasks.FileCatalog.Tests/​CatalogTests.cs Updates tests to provide AbsolutePath inputs via TaskEnvironment.Fallback.
src/​Common/​Internal/​AbsolutePathExtensions.cs Adds internal GetCanonicalForm() polyfill via Path.GetFullPath for fully-qualified inputs.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

FileInfo/DirectoryInfo are BCL types the analyzer already treats as safe via
.FullName, so the model layer keeps no Microsoft.Build.Framework dependency and
FileInfo.FullName supplies the canonicalization that GetAbsolutePath omits.
This removes the need for the internal GetCanonicalForm polyfill.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7

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.

Copilot review overview

🟡 Changes recommended

There are remaining correctness issues to address (notably disposal of schema resource streams in XlfDocument and updating impacted documentation crefs after the FileInfo API shift).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 1 Medium severity · 1 Low severity

New issues introduced by this change (1)
Severity Finding
Low severity src/​Microsoft.DotNet.XliffTasks/​Model/​Document.cs — This PR changes Document.Save from Save(string) to Save(FileInfo), but at least one XML doc…
Pre-existing issues (1)
Severity Finding
Medium severity src/​Microsoft.DotNet.XliffTasks/​Model/​XlfDocument.cs — CreateSchemaSet() allocates resource streams and XmlReaders without disposing them. Even though… View comment
Suppressed comments (1)

src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs:318

  • CreateSchemaSet creates manifest resource streams and XmlReaders without disposing them. Since this is now called once and cached for the lifetime of the process via Lazy, it can permanently leak handles/memory. Use using for the streams/readers (and consider throwing a clear error if the embedded resource stream is null).
        System.IO.Stream xmlSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xml.xsd");
        XmlReader xmlSchemaReader = XmlReader.Create(xmlSchemaResourceStream);
        System.IO.Stream xliffSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xliff-core-1.2-transitional.xsd");
        XmlReader xliffSchemaReader = XmlReader.Create(xliffSchemaResourceStream);

Task classes carry AbsolutePath and convert at the call boundary into Document,
CatalogBuilder and CatalogEntry, which stay on FileInfo so they keep no
Microsoft.Build.Framework dependency.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
Copilot AI review requested due to automatic review settings September 8, 2026 11:16

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.

Copilot review overview

🟡 Changes recommended

There are at least two correctness/robustness issues (a potentially-missed FileNotFoundException catch filter due to path canonicalization and undisposed schema resources) that should be addressed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 2 Medium severity · 1 Low severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​Microsoft.DotNet.XliffTasks/​Tasks/​UpdateXlf.cs — The catch filter compares FileNotFoundException.FileName to absoluteXlfPath.Value, but XlfDocument…
Pre-existing issues (2)
Severity Finding
Medium severity src/​Microsoft.DotNet.XliffTasks/​Model/​XlfDocument.cs — CreateSchemaSet() allocates resource streams and XmlReaders without disposing them. Even though… View comment
Low severity src/​Microsoft.DotNet.XliffTasks/​Model/​Document.cs — This PR changes Document.Save from Save(string) to Save(FileInfo), but at least one XML doc… View comment
Suppressed comments (1)

src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs:318

  • CreateSchemaSet creates resource streams and XmlReaders without disposing them. Even though this runs once per process, leaving these IDisposable resources undisposed can leak handles/memory in long-lived MSBuild nodes (especially with node reuse).
        System.IO.Stream xmlSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xml.xsd");
        XmlReader xmlSchemaReader = XmlReader.Create(xmlSchemaResourceStream);
        System.IO.Stream xliffSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xliff-core-1.2-transitional.xsd");
        XmlReader xliffSchemaReader = XmlReader.Create(xliffSchemaResourceStream);

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
Copilot AI review requested due to automatic review settings September 8, 2026 11:30

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.

Copilot review overview

🔵 Needs a closer look

A couple of the updated model-layer APIs introduce avoidable runtime issues (missing argument validation and undisposed schema readers/streams) that should be corrected before merging.

Review tier: Lite
Findings: 2 Medium severity · 1 Low severity

Pre-existing issues (3)
Severity Finding
Medium severity src/​Microsoft.DotNet.XliffTasks/​Tasks/​UpdateXlf.cs — The catch filter compares FileNotFoundException.FileName to absoluteXlfPath.Value, but XlfDocument… View comment
Medium severity src/​Microsoft.DotNet.XliffTasks/​Model/​XlfDocument.cs — CreateSchemaSet() allocates resource streams and XmlReaders without disposing them. Even though… View comment
Low severity src/​Microsoft.DotNet.XliffTasks/​Model/​Document.cs — This PR changes Document.Save from Save(string) to Save(FileInfo), but at least one XML doc… View comment
Suppressed comments (3)

Previously missed (1) — in code that hasn't changed since the last review.

src/Microsoft.DotNet.XliffTasks/Model/Document.cs:32

  • Document.Load(FileInfo) no longer validates its argument. Passing null now causes a NullReferenceException when accessing path.FullName, whereas the prior string-based implementation would throw an ArgumentNullException from the BCL call.

This issue also appears on line 59 of the same file.

src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs:318

  • CreateSchemaSet creates manifest-resource streams and XmlReaders but never disposes them. Since the schema set is compiled immediately, these can be safely disposed to avoid leaking handles/resources.
        System.IO.Stream xmlSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xml.xsd");
        XmlReader xmlSchemaReader = XmlReader.Create(xmlSchemaResourceStream);
        System.IO.Stream xliffSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xliff-core-1.2-transitional.xsd");
        XmlReader xliffSchemaReader = XmlReader.Create(xliffSchemaResourceStream);

src/Microsoft.DotNet.XliffTasks/Model/Document.cs:71

  • Document.Save(FileInfo) also lacks null-argument validation, which can produce a NullReferenceException (path or path.Directory) instead of a clear argument error. Adding an explicit guard keeps failures deterministic and easier to diagnose.
    public void Save(FileInfo path)
    {
        //On Windows:
        // Readers will prevent the file from being overwritten due to FileShare.Read.
        // Readers can read in parallel, but when there's contention with a writer, the retrying will kick in to resolve it.
        //On Unix:
        // FileShare.Read does nothing, but...
        // File.Replace is implemented with rename system call that will mean that even though writers can overwrite while 
        // reading is happening, each reader will see file before or after overwrite, not in between

        EnsureContent();
        string tempPath = Path.Combine(path.Directory.FullName, Path.GetRandomFileName());

…FoundException filter, fix stale cref

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
Copilot AI review requested due to automatic review settings September 8, 2026 12:03

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.

Copilot review overview

🔵 Needs a closer look

There is at least one concrete correctness issue in updated documentation comments (malformed XML doc tag) that should be fixed before approval.

Review tier: Lite
Findings: 1 Low severity

Pre-existing issues (1)
Severity Finding
Low severity src/​Microsoft.DotNet.XliffTasks/​Model/​Document.cs — This PR changes Document.Save from Save(string) to Save(FileInfo), but at least one XML doc… View comment
Issues resolved since last review (2)
Severity Finding
Medium severity src/​Microsoft.DotNet.XliffTasks/​Tasks/​UpdateXlf.cs — The catch filter compares FileNotFoundException.FileName to absoluteXlfPath.Value, but XlfDocument… View resolved comment
Medium severity src/​Microsoft.DotNet.XliffTasks/​Model/​XlfDocument.cs — CreateSchemaSet() allocates resource streams and XmlReaders without disposing them. Even though… View resolved comment
Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/Microsoft.DotNet.XliffTasks/Model/TranslatableNode.cs:38

  • The XML documentation comment is not well-formed: the tag opened on line 34 is never closed (line 37 re-opens instead). This can break documentation generation and produce compiler warnings (e.g., CS1570) if/when XML docs are enabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
Copilot AI review requested due to automatic review settings September 8, 2026 13:14

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.

Copilot review overview

🔵 Needs a closer look

It changes core build-task execution semantics (in-proc multithreading and path canonicalization) across multiple task areas, which warrants final human validation despite no specific issues found in review.

Review tier: Lite
Findings: None

Issues resolved since last review (1)
Severity Finding
Low severity src/​Microsoft.DotNet.XliffTasks/​Model/​Document.cs — This PR changes Document.Save from Save(string) to Save(FileInfo), but at least one XML doc… View resolved comment

@ViktorHofer
ViktorHofer merged commit a9b1583 into dotnet:main Sep 8, 2026
12 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 9, 2026
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.

3 participants