Skip to content

Fix main build break: remove redundant DisplayName=nameof in dotnet.Tests (MSTEST0071)#54938

Merged
Evangelink merged 1 commit into
mainfrom
evangelink-fix-dotnettests-mstest0071-displayname
Jun 23, 2026
Merged

Fix main build break: remove redundant DisplayName=nameof in dotnet.Tests (MSTEST0071)#54938
Evangelink merged 1 commit into
mainfrom
evangelink-fix-dotnettests-mstest0071-displayname

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Problem

main is currently failing to build (dotnet.Tests.csproj) with 48 error MSTEST0071:

test/dotnet.Tests/CommandTests/New/DotnetAddPostActionTests.cs(37,10): error MSTEST0071:
  The 'DisplayName' is the same as the test method name 'AddRefFindsOneDefaultProjFileInOutputDirectory' and can be removed

Root cause

The testfx dependency bump (#54765) merged after the dotnet.Tests MSTest migration (#54905). Under MSTestAnalysisMode=Recommended (set in test/Directory.Build.props), the analyzer now promotes MSTEST0071 to an error. The migrated New post-action tests use [TestMethod(DisplayName = nameof(MethodName))], where the display name is identical to the method name — exactly what MSTEST0071 flags as redundant.

This breaks the build for every PR that merges with current main (e.g. observed while investigating #54904).

Fix

Drop the redundant DisplayName = nameof(...) from the 24 affected [TestMethod] attributes across:

  • test/dotnet.Tests/CommandTests/New/DotnetAddPostActionTests.cs
  • test/dotnet.Tests/CommandTests/New/DotnetRestorePostActionTests.cs
  • test/dotnet.Tests/CommandTests/New/DotnetSlnPostActionTests.cs

The display name now defaults to the method name — identical observable behavior, no test renames.

Scope notes

  • Only dotnet.Tests (an MSTest.Sdk project) is affected. The TemplateEngine unit-test projects also use DisplayName = nameof, but they are still xUnit (Microsoft.NET.Sdk), so MSTEST0071 does not apply and they are intentionally left untouched.
  • This is split out from Migrate dotnet-new.IntegrationTests to MSTest.Sdk on MTP #54904 (which only fixes a separate CS0104 in dotnet-new.IntegrationTests) per the same incremental-migration approach.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

The testfx bump (#54765) elevated MSTEST0071 to an error under MSTestAnalysisMode=Recommended, breaking main: the dotnet.Tests New post-action tests set [TestMethod(DisplayName = nameof(Method))], which MSTEST0071 flags as redundant. Drop the DisplayName so the display name defaults to the method name.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 23, 2026 11: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.

Pull request overview

Fixes a dotnet.Tests build break on main caused by MSTest analyzers promoting MSTEST0071 (redundant DisplayName matching the method name) to an error under MSTestAnalysisMode=Recommended.

Changes:

  • Removes redundant [TestMethod(DisplayName = nameof(...))] usage where the display name equals the test method name.
  • Replaces those attributes with plain [TestMethod] across the affected dotnet new post-action test files.
Show a summary per file
File Description
test/dotnet.Tests/CommandTests/New/DotnetAddPostActionTests.cs Drops redundant DisplayName = nameof(...) from [TestMethod] attributes to satisfy MSTEST0071.
test/dotnet.Tests/CommandTests/New/DotnetRestorePostActionTests.cs Same: removes redundant DisplayName from [TestMethod].
test/dotnet.Tests/CommandTests/New/DotnetSlnPostActionTests.cs Same: removes redundant DisplayName from [TestMethod] (including solution-related post-action tests).

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 0

@Evangelink Evangelink enabled auto-merge June 23, 2026 12:24
@Evangelink

Copy link
Copy Markdown
Member Author

/ba-g test failures are unrelated to this PR. Merging to unblock main.

@Evangelink Evangelink merged commit 77b4666 into main Jun 23, 2026
25 of 27 checks passed
@Evangelink Evangelink deleted the evangelink-fix-dotnettests-mstest0071-displayname branch June 23, 2026 15:27
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 24, 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