title: Why #pragma warning disable S2068 does not work?
body: <p>I have the following piece of code in a tool:</p>
  <pre><code>var o = new OptionSet()
      .Add(&quot;password=|pwd=|p=&quot;, &quot;The database password. Only when using SQL authentication.&quot;, p =&gt; password = p.TrimQuotes())
      ...
  ;
  </code></pre>
  <p>My PR build promotes Sonar warnings to compilation errors and so the code fails with:</p>
  <pre><code>HashPasswordsArgs.cs(49,22): warning S2068: &quot;password&quot; detected here, make sure this is not a hard-coded credential. [C:\xyz\HashPasswords\src\HashPasswords\HashPasswords.csproj]
  </code></pre>
  <p>OK, I know it is a false positive and want to suppress it in code (this is my specific and conscious desire, please do not suggest going to the SonarQube server to do anything).</p>
  <p>I tried adding the <code>//NOSONAR</code> (with or without a space after //), I also tried adding <code>#pragma warning disable S2068</code> at the top of the file. Nothing helps.</p>
  <p>What am I missing?</p>
  <p>Here are the example runs:</p>
  <p><strong>//NOSONAR</strong></p>
  <pre><code>C:\xyz\HashPasswords [master ≡]&gt; cat .\src\HashPasswords\HashPasswordsArgs.cs |sls SONAR
  
                  .Add(&quot;password=|pwd=|p=&quot;, &quot;The database password. Only when using SQL authentication.&quot;, p =&gt; password = p.TrimQuotes()) //NOSONAR
  
  
  C:\xyz\HashPasswords [master ≡ +1 ~2 -0 !]&gt; dotnet build
  Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core
  Copyright (C) Microsoft Corporation. All rights reserved.
  
    Determining projects to restore...
    All projects are up-to-date for restore.
  HashPasswordsArgs.cs(49,22): warning S2068: &quot;password&quot; detected here, make sure this is not a hard-coded credential. [C:\xyz\HashPasswords\src\HashPasswords\HashPasswords.csproj]
    HashPasswords -&gt; C:\xyz\HashPasswords\src\HashPasswords\bin\Debug\net472\HashPasswords.exe
    Sonar: (HashPasswords.csproj) Project processed successfully
  
  Build succeeded.
  
  HashPasswordsArgs.cs(49,22): warning S2068: &quot;password&quot; detected here, make sure this is not a hard-coded credential. [C:\xyz\HashPasswords\src\HashPasswords\HashPasswords.csproj]
      1 Warning(s)
      0 Error(s)
  
  Time Elapsed 00:00:01.23
  C:\xyz\HashPasswords [master ≡ +1 ~2 -0 !]&gt;
  </code></pre>
  <p><strong>#pragma warning disable S2068</strong></p>
  <pre><code>C:\xyz\HashPasswords [master ≡ +1 ~2 -0 !]&gt; dir .\src\HashPasswords\HashPasswordsArgs.cs |sls S2068
  
  src\HashPasswords\HashPasswordsArgs.cs:6:#pragma warning disable S2068
  
  
  C:\xyz\HashPasswords [master ≡ +1 ~2 -0 !]&gt; dotnet build
  Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core
  Copyright (C) Microsoft Corporation. All rights reserved.
  
    Determining projects to restore...
    All projects are up-to-date for restore.
  HashPasswordsArgs.cs(51,22): warning S2068: &quot;password&quot; detected here, make sure this is not a hard-coded credential. [C:\xyz\HashPasswords\src\HashPasswords\HashPasswords.csproj]
    HashPasswords -&gt; C:\xyz\HashPasswords\src\HashPasswords\bin\Debug\net472\HashPasswords.exe
    Sonar: (HashPasswords.csproj) Project processed successfully
  
  Build succeeded.
  
  HashPasswordsArgs.cs(51,22): warning S2068: &quot;password&quot; detected here, make sure this is not a hard-coded credential. [C:\xyz\HashPasswords\src\HashPasswords\HashPasswords.csproj]
      1 Warning(s)
      0 Error(s)
  
  Time Elapsed 00:00:01.28
  C:\xyz\HashPasswords [master ≡ +1 ~2 -0 !]&gt;
  </code></pre>
  <p>I am interested to know why #pragma does not work. Any other code based suppression is welcome. The more focused the better, i.e. ideally I just want to suppress this one warning on the particular line.</p>