sonar-dotnet icon indicating copy to clipboard operation
sonar-dotnet copied to clipboard

NET-1892 S3904 FP: on projects without assemblies

Open alexthornton1 opened this issue 4 years ago • 3 comments

Description

S3904 is being applied to projects built with the Microsoft.Build.NoTargets SDK, even though these projects do not actually produce an assembly. The error refers to a lack of an AssemblyVersion attribute on the assembly, but, in this case, there's no assembly on which to place such an attribute.

In my case, the projects are used to perform custom NuGet packaging work, but that doesn't appear to be an important part of the issue, as I've been able to boil it all the way down to a nearly empty solution that exhibits the same problem.

Repro steps

I've attached the simplest repro that I could put together that exhibits the same problem that I'm finding in practice. It's a solution with two projects:

  1. A class library named SonarQube.Lib containing no code.
  2. A project named SonarQube.NoTargets that uses the Microsoft.Build.NoTargets SDK and references SonarQube.Lib, which causes SonarQube.NoTargets to be built last (consistent with my real-world situation).

SonarQube.NoTargets.zip

Expected behavior

I would expect not to receive a warning S3904 in this case, as there is no assembly.

Actual behavior

When I run code analysis in Visual Studio 2019 (by choosing the Analyze menu, then Run Code Analysis, then On Solution) with the SonarLint for Visual Studio 2019 extension (version 4.37.0.34839) installed, I'm receiving a warning S3904 referring to a non-existent assembly.

image

Known workarounds

Since there's no code in this project, there's no way to include SuppressMessage attributes that suppress these warnings. I expect there's another way to configure these kinds of suppressions, but I'm relatively new to SonarQube, so am not clear on what to do, so I'm simply accepting that the warning exists for now (since it's the only one I'm seeing).

Related information

Visual Studio 2019 Enterprise (version 16.11.0) SonarLint for Visual Studio 2019 extension (version 4.37.0.34839) .NET 5.0.400 Windows 10 (version 1909)

alexthornton1 avatar Aug 26 '21 21:08 alexthornton1

Hi @alexthornton1,

I can confirm the issue, thanks a lot for your feedback.

Been a hot minute since this issue was opened so I wanted to share. If you drop this file into the sql proj directory it should suppress the warnings during build or at least it does for me when running dotnet build.

Directory.Build.props

<Project>
  <PropertyGroup>
    <!--
    S3904: Sql projects do not produce assemblies
    -->
    <NoWarn>S3904</NoWarn>
  </PropertyGroup>
</Project>

RiverHeart avatar Mar 04 '25 22:03 RiverHeart

Internal ticket NET-1892