Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SonarLint for Visual Studio 2017 plugin does not respect shared imports #658

Closed
t03apt opened this issue Jun 7, 2018 · 4 comments
Closed
Assignees
Labels
Area: Connected Mode Forum Issues that belong in the forum

Comments

@t03apt
Copy link

t03apt commented Jun 7, 2018

SonarLint for Visual Studio 2017 does not work well with shared imports.

I am using Directory.Build.props to import many code analyzers to all projects.
A custom .ruleset file is also specified there.
Here I am importing the other .ruleset generated by the SonarLint plugin.

SonarLint VS plugin does not recognize these shared imports.
When I click on Update in 'Test Explorer - Sonar Qube' window, it always creates needles rulesets for each projects. For example: \ClassLibrary1\ClassLibrary1.ruleset.
It also inserts needless PropertyGroups to .csproj files like

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <CodeAnalysisRuleSet>ClassLibrary1.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <CodeAnalysisRuleSet>ClassLibrary1.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>

Note: I removed .sonarlint\TestSonarlint.slconfig from the example repository because it has some confidential information.

@t03apt
Copy link
Author

t03apt commented Jun 7, 2018

SonarLint VS plugin also can't update <PackageReference Include="SonarAnalyzer.CSharp" Version="..." /> defined in Directory.Build.props.

@duncanp-sonar duncanp-sonar added the Forum Issues that belong in the forum label Jul 24, 2018
@duncanp-sonar
Copy link
Contributor

@t03apt agreed, SLVS doesn't work well if you have manually configured your solution.
SLVS is using VS extensibility interfaces to set the ruleset (IVSBuildPropertyStorage) and to update the NuGet packages (IVSPackageInstaller). Neither of these interfaces give much control over where the settings are stored (e.g. the IVSPackageInstaller always seems to update the main project file) so there may not be much we can do about updating a Directory.Build.props files instead.

However, we might be able to do a better job of detecting that a project is already configured and so not prompt to update.

Also, as of v4 SonarLint for Visual Studio won't add the NuGet package references to every project, Instead, it relies on the analyzers embedded in the VSIX, so that should be one less problem.

@duncanp-sonar
Copy link
Contributor

FYI I've created #790 to track one of the specific issues raised in this ticket. That bug will be fixed in the next version of SLVS.

@duncanp-sonar
Copy link
Contributor

FYI I've added a separate issue about adding unconditional ruleset property references: #805

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Connected Mode Forum Issues that belong in the forum
Projects
None yet
Development

No branches or pull requests

2 participants