question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Analyzers do not work with GlobalUsings

See original GitHub issue

Description

When using global usings, analyzers no longer report any diagnostics.

Expected behavior:

Be able to use global usings, either:

  • From a source file GlobalUsings.cs that contains:
    global using Xunit;
    global using FluentAssertions;
    
    with the next snippet in project file:
    <ItemGroup>
      <Compile Include="GlobalUsings.cs" />
    </ItemGroup>
    
  • From project file directly:
    <ItemGroup>
      <Using Include="FluentAssertions" />
      <Using Include="Xunit" />
    </ItemGroup>
    

Versions

  • Fluent Assertions: 6.7.0
  • Fluent Assertions Analyzers: 0.17.2
  • .NET 6

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bart-vmwarecommented, Aug 5, 2022

Another source for inspiration: The Sonar analyzer for S2699: Tests should include assertions, which supports xUnit and FluentAssertions. These analyzers are widely-used and optimized for high performance in large codebases. Source code at https://github.com/SonarSource/sonar-dotnet/blob/18eb2f6d6c4655f8b259744ef210347d12ce8b94/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldContainAssertion.cs.

0reactions
bart-vmwarecommented, Jul 11, 2023

Thanks for the fix, this is working correctly now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Why does StyleCopAnalyzers think that global usings ...
Why does StyleCopAnalyzers think that global usings should be declared within a namespace, when such syntax is not possible?
Read more >
IDE0065: Global usings must not be places inside ...
Steps to Reproduce: Add a Usings.cs with following code. global using System.Text;. Run dotnet format. Expected Behavior: Expected to format to ...
Read more >
GlobalUsingsAnalyzer 1.4.0
A C# analyzer that will suggest moving usings to a single project file. Defaults to GlobalUsings.cs but can be changed using a .editorconfig...
Read more >
Welcome to C# 10 - .NET Blog
The scope of global usings is the current compilation, which generally corresponds to the current project. For more information, see global ...
Read more >
Project property settings in Visual Studio - .NET MAUI
Describes the Visual Studio project properties available to a .NET MAUI app. The properties and settings are related to building the app, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found