MSBuild.Sdk.SqlProj: Inline IGNORE comments for SqlServer.Rules are being ignored
After upgrading to 2.7.1, I enabled code analysis via <RunSqlCodeAnalysis>True</RunSqlCodeAnalysis>. Following the SqlServer.Rules documentation, I initially added ignored rules via the .csproj file, such as this: <CodeAnalysisRules>-SqlServer.Rules.SRD0002</CodeAnalysisRules>, and this worked; however, when moving into the specific SQL file in question (and removing from the .csproj), the rule started being enforced again (not ignored). I tried all the forms of inline syntax. Here’s a simple example of a file:
-- IGNORE SRD0002
CREATE TABLE [dbo].[Version]
(
[Current] NVARCHAR(100) NOT NULL
)
This should be ignoring the SRD0002 rule; however, it still shows up when building the project:
If I add this back into the .csproj (as shown above), it goes back to correctly ignoring this.
If this is in fact an issue with SqlServer.Rules I can report the issue there instead, but thought I would start here as I’m unfamiliar with how these rules and their ignore mechanisms are integrated into this project.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19
Commits related to this issue
- Enable support for StaticCodeAnalysis.SuppressMessages.xml to suppress rules for individual files fixes #578 — committed to ErikEJ/MSBuild.Sdk.SqlProj by ErikEJ 2 years ago
- Enable support for StaticCodeAnalysis.SuppressMessages.xml (#643) * Enable support for StaticCodeAnalysis.SuppressMessages.xml to suppress rules for individual files fixes #578 * fix typos ... — committed to ErikEJ/MSBuild.Sdk.SqlProj by ErikEJ 2 years ago
That’s great, thanks @ErikEJ. I’ll test it out. I’ll be especially interested to see whether it works correctly in a Linux-based system.
Finally got it to work, forgot to use backslash in the paths (on Windows) 😢
Let me see if we can add support for this in the SDK!
@medianick I just discovered that DaacFX codeanalysis support a XML file for exclusions: https://learn.microsoft.com/en-us/sql/tools/sql-database-projects/concepts/sql-code-analysis/sql-code-analysis?view=sql-server-ver16&pivots=sq1-visual-studio#sql-project-file-sample-and-syntax. Not really sure where it must be placed to be picked up, but mayb just together with the .dacpac being analyzed
@medianick any suggestions via a PR or discussion in my fork would be highly appreciated