Skip to content

Remove xUnit dependencies from shipping TemplateVerifier package - #55095

Merged
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/cleanup-templateverifier-xunit-deps
Jul 1, 2026
Merged

Evangelink merged 2 commits into
mainfrom
dev/amauryleve/cleanup-templateverifier-xunit-deps

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Summary

Microsoft.TemplateEngine.Authoring.TemplateVerifier is now a shipping package, but it still pulled in three xUnit v3 packages. This removes them and replaces their usages with framework-agnostic equivalents so the shipping package no longer depends on any test framework.

Removed PackageReferences:

  • Verify.XunitV3
  • xunit.v3.assert
  • xunit.v3.extensibility.core

What each dependency was used for, and the replacement

  1. Verify.XunitV3 → the DefaultVerifyDirectory fallback (VerifyXunit.Verifier.VerifyDirectory). Removed. VerificationEngine.DirectoryVerifier is now required — when unset, snapshot verification throws a clear localized InvalidOperationException pointing the consumer at DirectoryVerifier / WithCustomDirectoryVerifier. Every in-repo consumer already injects VerifyMSTest.Verifier.VerifyDirectory.

  2. xunit.v3.assert → Assert.True/False/NotNull in the shared CommandResultAssertions.cs. Replaced with local AssertTrue/AssertFalse/AssertNotNull helpers (nullable-annotated with [DoesNotReturnIf]/[NotNull]) that throw a new internal CommandResultAssertionException.

  3. xunit.v3.extensibility.core → provided Xunit.ITestOutputHelper, referenced by the shared command runner's ITestOutputHelper overloads (the package itself only uses the ILogger overloads). Added a package-owned internal ITestOutputHelper in the Microsoft.TemplateEngine.CommandUtils namespace, mirroring the repo's runner-agnostic Microsoft.NET.TestFramework.ITestOutputHelper shape, so the short name resolves without any test framework.

Also dropped the now-obsolete <IsTestProject /> hack in the shared props (it only existed to counter xunit.props).

Localization

Added VerificationEngine_Error_NoDirectoryVerifier to LocalizableStrings.resx; the .xlf files were regenerated via the build's UpdateXlf target (entries are state="new"), not hand-edited.

Validation

  • TemplateVerifier package: builds with 0 warnings, 0 errors, no xUnit deps.
  • Shipping consumers Authoring.CLI and TemplateApiVerifier: build clean.
  • CLI.IntegrationTests (MSTest; exercises the internal BasicCommand via InternalsVisibleTo, plus Verify.MSTest): builds clean — confirms the IVT surface and ILogger overloads are intact.

Behavior / breaking-change note

Removing the built-in xUnit default verifier is a breaking change for any external consumer that relied on it without injecting a DirectoryVerifier — they will now get the explanatory error and must set one (or provide a custom verifier). All internal consumers already inject a verifier.

The Microsoft.TemplateEngine.Authoring.TemplateVerifier package is now shipping, but it pulled in three xUnit v3 packages (Verify.XunitV3, xunit.v3.assert, xunit.v3.extensibility.core). Replace their usages with framework-agnostic equivalents:

- Verify.XunitV3: remove the DefaultVerifyDirectory xUnit fallback. DirectoryVerifier is now required; when unset, snapshot verification throws a clear InvalidOperationException. All in-repo consumers already inject VerifyMSTest.Verifier.VerifyDirectory.
- xunit.v3.assert: replace Assert.True/False/NotNull in the shared CommandResultAssertions.cs with local helpers that throw CommandResultAssertionException.
- xunit.v3.extensibility.core: it provided Xunit.ITestOutputHelper for the shared command runner overloads (the package only uses the ILogger overloads). Add a package-owned internal ITestOutputHelper so the short name resolves without any test framework.

Also drop the now-obsolete IsTestProject hack in the shared props.

Co-authored-by: Copilot App <[email protected]>
Copilot AI review requested due to automatic review settings July 1, 2026 11:19
@Evangelink
Evangelink requested a review from a team as a code owner July 1, 2026 11:19

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 pull request removes xUnit v3 dependencies from the now-shipping Microsoft.TemplateEngine.Authoring.TemplateVerifier package by replacing the remaining xUnit-specific hooks with framework-agnostic equivalents, so the shipping package no longer depends on a test framework.

Changes:

  • Remove xUnit/Verify.xUnit package references and require consumers to provide VerificationEngine.DirectoryVerifier (or a per-call custom verifier), with a localized error when missing.
  • Replace shared xUnit Assert.* usages with local assertion helpers throwing a package-owned exception.
  • Introduce an internal, package-owned ITestOutputHelper abstraction to satisfy shared command-runner sources without referencing xUnit.
Show a summary per file
File Description
src/TemplateEngine/Tools/Shared/Microsoft.TemplateEngine.CommandUtils/CommandResultAssertions.cs Replaces xUnit asserts with local assertion helpers and a custom exception.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/VerificationEngine.cs Removes xUnit default verifier fallback; throws localized error if DirectoryVerifier is unset.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/Microsoft.TemplateEngine.Authoring.TemplateVerifier.Shared.props Drops the obsolete IsTestProject workaround tied to xUnit props.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/Microsoft.TemplateEngine.Authoring.TemplateVerifier.csproj Removes xUnit/Verify.xUnit package references from the shipping project.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/LocalizableStrings.resx Adds localized string for missing directory verifier configuration.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/ITestOutputHelper.cs Adds internal framework-agnostic ITestOutputHelper interface for shared command utils sources.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.zh-Hant.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.zh-Hans.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.tr.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.ru.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.pt-BR.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.pl.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.ko.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.ja.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.it.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.fr.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.es.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.de.xlf Adds new localization entry for the missing directory verifier error.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/xlf/LocalizableStrings.cs.xlf Adds new localization entry for the missing directory verifier error.

Copilot's findings

  • Files reviewed: 19/19 changed files
  • Comments generated: 1

Removing the built-in xUnit default verifier from TemplateVerifier had two fallout effects addressed here:

- The shipping dotnet-template-authoring 'verify' command relied on the built-in default verifier. Inject VerifyXunit.Verifier.VerifyDirectory in the CLI's Program.Main so the command keeps working (the CLI already referenced Verify.XunitV3).
- Dropping Verify.XunitV3 from TemplateVerifier downgraded its transitive Verify from 28.12.0 to 27.0.0 (Verify.DiffPlex floor), pulling EmptyFiles 8.4.0 while the CLI still resolved 8.7.1. Publishing the tool then failed with NETSDK1152 (duplicate EmptyFiles). Pin Verify core to 28.12.0 in TemplateVerifier via VersionOverride so both projects resolve the same EmptyFiles, matching the pre-change state.

Also fix a misleading failure message in NotHaveStdErrContaining (it said 'contain ... but it did not' for a not-contains assertion), per review feedback.

Co-authored-by: Copilot App <[email protected]>
@Evangelink
Evangelink enabled auto-merge July 1, 2026 15:26
@marcpopMSFT
marcpopMSFT requested a review from baronfel July 1, 2026 16:48
@joeloff

joeloff commented Jul 1, 2026

Copy link
Copy Markdown
Member

Taking a look at this today

<!-- Verify core is used directly (VerifySettings, SettingsTask, FileScrubber). Pin it to the same
version the Authoring.CLI tool resolves (via Verify.XunitV3) so the two projects don't contribute
different EmptyFiles versions to the CLI's publish output, which would fail with NETSDK1152. -->
<PackageReference Include="Verify" VersionOverride="28.12.0" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe I'm missing something here. CPM ensures everyone uses the same version, overriding allows you to diverge, so isn't this potentially the opposite of pinning?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right that VersionOverride normally lets a project diverge from the CPM-pinned version, which is the opposite of the usual goal. I looked into moving Verify into CPM instead, but it turns out this repo genuinely needs two different Verify versions side by side:

  • 28.12.0, pulled in via Verify.XunitV3 by the shipping Authoring.CLI/TemplateSearch toolchain
  • 31.19.0, pulled in via Verify.MSTest by the test projects

Adding a single centrally-managed Verify version can't satisfy both. Pinning to 28.12.0 produces NU1109 package-downgrade errors in every MSTest-based test project (they need >= 31.19.0 transitively); pinning to 31.19.0 breaks the CLI's publish output with NETSDK1152 (mismatched EmptyFiles versions). I verified both failure modes locally.

So VersionOverride here is actually doing targeted pinning: it aligns just this one shipping project to the same 28.12.0 the CLI resolves, without disturbing the test projects. I've kept the mechanism but expanded the comment to explain exactly this in the follow-up PR #55131.

{
if (value is null)
{
throw new CommandResultAssertionException("Expected value to not be null but it was.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
throw new CommandResultAssertionException("Expected value to not be null but it was.");
throw new CommandResultAssertionException("Expected value to not be null, but it was.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few other messages have the same issue

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch - fixed in the follow-up PR #55131. Added a comma before "but" across all the assertion messages in this file (21 in total), not just this one.

@Evangelink
Evangelink merged commit 3c75598 into main Jul 1, 2026
37 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/cleanup-templateverifier-xunit-deps branch July 1, 2026 21:08
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 6, 2026
Evangelink added a commit that referenced this pull request Jul 13, 2026
… VersionOverride rationale

Co-authored-by: Copilot App <[email protected]>
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