Repository navigation
Remove xUnit dependencies from shipping TemplateVerifier package - #55095
Conversation
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]>
There was a problem hiding this comment.
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
ITestOutputHelperabstraction 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]>
|
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" /> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 viaVerify.XunitV3by the shippingAuthoring.CLI/TemplateSearchtoolchain31.19.0, pulled in viaVerify.MSTestby 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."); |
There was a problem hiding this comment.
| throw new CommandResultAssertionException("Expected value to not be null but it was."); | |
| throw new CommandResultAssertionException("Expected value to not be null, but it was."); |
There was a problem hiding this comment.
A few other messages have the same issue
There was a problem hiding this comment.
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.
… VersionOverride rationale Co-authored-by: Copilot App <[email protected]>
Summary
Microsoft.TemplateEngine.Authoring.TemplateVerifieris 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.XunitV3xunit.v3.assertxunit.v3.extensibility.coreWhat each dependency was used for, and the replacement
Verify.XunitV3→ theDefaultVerifyDirectoryfallback (VerifyXunit.Verifier.VerifyDirectory). Removed.VerificationEngine.DirectoryVerifieris now required — when unset, snapshot verification throws a clear localizedInvalidOperationExceptionpointing the consumer atDirectoryVerifier/WithCustomDirectoryVerifier. Every in-repo consumer already injectsVerifyMSTest.Verifier.VerifyDirectory.xunit.v3.assert→Assert.True/False/NotNullin the sharedCommandResultAssertions.cs. Replaced with localAssertTrue/AssertFalse/AssertNotNullhelpers (nullable-annotated with[DoesNotReturnIf]/[NotNull]) that throw a new internalCommandResultAssertionException.xunit.v3.extensibility.core→ providedXunit.ITestOutputHelper, referenced by the shared command runner'sITestOutputHelperoverloads (the package itself only uses theILoggeroverloads). Added a package-owned internalITestOutputHelperin theMicrosoft.TemplateEngine.CommandUtilsnamespace, mirroring the repo's runner-agnosticMicrosoft.NET.TestFramework.ITestOutputHelpershape, so the short name resolves without any test framework.Also dropped the now-obsolete
<IsTestProject />hack in the shared props (it only existed to counterxunit.props).Localization
Added
VerificationEngine_Error_NoDirectoryVerifiertoLocalizableStrings.resx; the.xlffiles were regenerated via the build'sUpdateXlftarget (entries arestate="new"), not hand-edited.Validation
TemplateVerifierpackage: builds with 0 warnings, 0 errors, no xUnit deps.Authoring.CLIandTemplateApiVerifier: build clean.CLI.IntegrationTests(MSTest; exercises the internalBasicCommandviaInternalsVisibleTo, plusVerify.MSTest): builds clean — confirms the IVT surface andILoggeroverloads 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.