Skip to content

Remove warning CS1701 and CS1702 when using RoslynCodeTaskFactory - #12346

Merged
SimaTian merged 9 commits into
dotnet:mainfrom
huulinhnguyen-dev:dev/huulinhnguyen/suppress_cs1701_cs1702_warnings
Sep 24, 2025
Merged

SimaTian merged 9 commits into
dotnet:mainfrom
huulinhnguyen-dev:dev/huulinhnguyen/suppress_cs1701_cs1702_warnings

Conversation

@huulinhnguyen-dev

Copy link
Copy Markdown
Contributor

Fixes #
Fix the issue: Suppress CS1701 and CS1702 warnings by default in RoslynCodeTaskFactory to align with .NET SDK #12101

Context

When using RoslynCodeTaskFactory, MSBuild emits CS1701 and CS1702 assembly binding warnings for version mismatches (e.g., between System.Memory and System.Text.Json). These warnings are not actionable in modern .NET scenarios and are already suppressed by default in the .NET SDK and Roslyn. This issue causes unnecessary warning noise and confusion in custom task or non-SDK builds.

Changes Made

Added a new property in the task factory configuration to include NoWarn="1701;1702" for all tasks generated by RoslynCodeTaskFactory

Testing

Added a new unit test RoslynCodeTaskFactoryWithoutCS1702Warning in the MSBuild test suite to verify that no CS1702 warnings are emitted when using RoslynCodeTaskFactory with references to System.Memory (v4.6.3) and System.Text.Json (v9.0.7).

Create a project file base on example of user for test dotnet/roslyn#19640 (comment)

Notes

@JanProvaznik JanProvaznik left a comment

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.

Please don't commit the package dlls and xml files to the repo... This would increase maintenace burden and potentially cause security flagging in the future.

@huulinhnguyen-dev
huulinhnguyen-dev marked this pull request as draft August 21, 2025 08:51
@huulinhnguyen-dev
huulinhnguyen-dev marked this pull request as ready for review September 19, 2025 14:17

@JanProvaznik JanProvaznik left a comment

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.

:shipit:

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.

4 participants