Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling a specific C# 9 source generator

Is there any way to disable a specific C# 9 source generator? Or alternatively disable them all?

the package in question is https://github.com/Husqvik/GraphQlClientGenerator#c-9-source-generator which is mean to be able to be used as both a lib and a source generator. but those are mutually exclusive, ie the majority of use cases it make no sense to gen code both by executing code and by code gen

like image 411
Simon Avatar asked Feb 10 '21 02:02

Simon


People also ask

How do I disable a warning in C++?

To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction.

Is it possible to disable specific compiler warnings?

I have seen this queston: Is it possible to disable specific compiler warnings? but it is for Visual studio, not Visual Studio Code. 1. Solution Explorer > View > Properties > Build > Suppress Warnings

Why do I need a macro to disable warnings in C++?

That can happen if your application is deployed on multiple OSes, or if you write a library for the general population of C++ programmers. This is where the fun begins. Since disabling warnings is done at the level of the pre-processor, we’re going to need a macro.

How to disable pragma warning in Visual Studio Code?

#pragma warning( pop ) And to disable a specific warning, we need to write code like this: #pragma warning( disable : 4100 ) Remember, in Visual Studio warnings are identified with numbers, not names. If we have to suppress the warning in our example code on Visual Studio, we would write this:


1 Answers

seems this will disable all

<Target Name="DisableAnalyzers" 
        BeforeTargets="CoreCompile">
  <ItemGroup>
    <Analyzer Remove="@(Analyzer)" />
  </ItemGroup>
</Target>

removing a named one uses the file path

<Target Name="DisableAnalyzers"
        BeforeTargets="CoreCompile">
  <ItemGroup>
    <Analyzer Remove="D:\nugets\nugetx\0.9.2\analyzers\dotnet\cs\NugetXAnalizer.dll" />
  </ItemGroup>
</Target>

ok and finally u can remove based on filename

<Target Name="DisableAnalyzers"
        BeforeTargets="CoreCompile">
  <ItemGroup>
    <Analyzer Remove="@(Analyzer)"
              Condition="'%(Filename)' == 'NugetXAnalizer'"/>
  </ItemGroup>
</Target>
like image 91
Simon Avatar answered Oct 13 '22 08:10

Simon