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:

image

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

Most upvoted comments

@medianick This feature is now included in the latest preview release https://www.nuget.org/packages/MSBuild.Sdk.SqlProj/3.0.0-beta.2

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) 😢

<?xml version="1.0" encoding="utf-8" ?>
<StaticCodeAnalysis version="2" xmlns="urn:Microsoft.Data.Tools.Schema.StaticCodeAnalysis">
  <SuppressedFile FilePath="dbo\Procedures\Procedure1.sql">
	<SuppressedRule Category="Microsoft.Rules.Data" RuleId="SR0001" />
	<SuppressedRule Category="Microsoft.Rules.Data" RuleId="SR0016" />
  </SuppressedFile>
</StaticCodeAnalysis>

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