fix(tests): normalize test SDK + restore OutputType=Exe for MTP - #331
Conversation
The prior normalization commit removed the explicit <OutputType>Exe/> in favor of Tests.targets auto-setting it. That auto-set runs inside the _DetectTestFrameworksAndMTP Target, which fires only at build time — 'dotnet test' evaluates OutputType statically before that and aborts with "A runnable project should target a runnable TFM ... The current OutputType is 'Library'." MTP also requires the .exe host, not a .dll library output. Setting OutputType=Exe in the csproj evaluates during props phase, so both 'dotnet build' and 'dotnet test' see Exe before any target runs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ghost
left a comment
There was a problem hiding this comment.
✅ Auto-approved by destructive auto-merge (admin tier)
|
@coderabbitai autofix |
ghost
left a comment
There was a problem hiding this comment.
✅ Auto-approved by destructive auto-merge (admin tier)
There was a problem hiding this comment.
Pull request overview
Low risk: test project SDK normalization/config-only changes; no runtime/production code paths touched.
Review Notes
Blockers: None found.
Important issues: None found.
Minor / optional: None found.
No blockers were found after checking CI/test integrity implications (MTP runner + OutputType), correctness of project configuration, duplication/unnecessary complexity, and security boundaries (no workflow/secret/auth changes).
Changes:
- Switch
qyl.mcp.teststoANcpLua.NET.Sdk.Testand rely on the SDK forIsTestProject. - Switch
qyl.collector.teststoANcpLua.NET.Sdk.Testand rely on the SDK forIsTestProject. - Keep explicit
<OutputType>Exe</OutputType>in both test projects to preserve Microsoft Testing Platform (dotnet test) behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/qyl.mcp.tests/qyl.mcp.tests.csproj | Move to ANcpLua.NET.Sdk.Test; keep OutputType=Exe for MTP. |
| tests/qyl.collector.tests/qyl.collector.tests.csproj | Move to ANcpLua.NET.Sdk.Test; keep OutputType=Exe for MTP. |
Summary
14b3246a)14b3246a)3d12f9a5) — regression fixWhy the SDK switch is safe for collector.tests
`ANcpLua.NET.Sdk.Test` is based on `Microsoft.NET.Sdk` (not `.Web`). `Microsoft.AspNetCore.Mvc.Testing` auto-adds the `Microsoft.AspNetCore.App` framework reference since .NET 6, so the `.Web` base SDK is not required. Build + test confirm both projects compile and run.
Why OutputType=Exe must stay explicit
`Tests.targets` in `ANcpLua.NET.Sdk` sets `OutputType=Exe` inside the `_DetectTestFrameworksAndMTP` Target. Targets fire at build time, but `dotnet test` evaluates `OutputType` statically before invoking the test platform — sees `Library`, aborts:
Setting `Exe` in the csproj evaluates during the props phase, so both `dotnet build` and `dotnet test` see `Exe` before any target runs. The .Test variant SDK auto-sets `IsTestProject=true` (via `Common.props` line 10), so that property is no longer needed in either csproj — but `OutputType` is.
Why `xunit.v3.mtp-v2` stays referenced
`Tests.targets` auto-injects `xunit.v3.mtp-v2` with `IsImplicitlyDefined="true"` and an explicit `Version`. Under CPM with `xunit.v3.mtp-v2` listed in `Directory.Packages.props`, this combination produces `NU1009` ("implicitly defined items cannot define a PackageVersion"). Until the SDK itself is fixed, consumers using CPM must keep an explicit `` to satisfy CPM resolution.
Test plan
Follow-up (separate)
The SDK's `Tests.targets` xUnit auto-injection is broken under CPM (NU1009). Fix in `ANcpLua.NET.Sdk`: drop `Version=` from the implicit `PackageReference` when CPM is enabled, or drop `IsImplicitlyDefined`. Will track in the SDK repo.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmithwith what you need.