# File exclusions

All versions of SonarQube for IDE will fetch file exclusions from SonarQube (Server, Cloud) or SonarQube Community Build when you bind a project while running in connected mode. Locally defined file exclusions will be ignored when running in connected mode.

For more information about how SonarQube for Visual Studio settings are handled by the server, look at the server documentation on setting your analysis scope:

* See the [Setting analysis scope](https://app.gitbook.com/s/LWhbesChsC4Yd1BbhHhS/project-administration/adjusting-analysis/setting-analysis-scope "mention") pages in SonarQube Server.
* See the [Analysis scope](https://app.gitbook.com/s/B4UT2GNiZKjtxFtcFAL7/managing-your-projects/project-analysis/setting-analysis-scope "mention") pages in SonarQube Cloud.
* See the [Setting analysis scope](https://app.gitbook.com/s/bqrfLGeD0Y9vE5l9Le42/project-administration/adjusting-analysis/setting-analysis-scope "mention") pages in SonarQube Community Build.

## Exclusions in the IDE <a href="#exclusions-in-the-ide" id="exclusions-in-the-ide"></a>

SonarQube for Visual Studio allows you to exclude files and solutions from local analysis as defined in the **SonarQube** > **Options** or in the **SonarQube** > **Solution Settings** extension windows.

When running in [setup](https://docs.sonarsource.com/sonarqube-for-visual-studio/connect-your-ide/setup "mention") with SonarQube (Server, Cloud) or SonarQube Community Build, SonarQube for IDE will ignore local exclusions and fetch exclusions from the SonarQube (Server, Cloud) or SonarQube Community Build server.

## Defining file exclusions <a href="#defining-file-exclusions" id="defining-file-exclusions"></a>

In Visual Studio, navigate to **Extensions** > **SonarQube** > **Options** > **File Exclusions** window and select **Add** to configure the file names and/or wild card patterns you want to exclude from the analysis. Select **OK** when finished.

<div align="left"><figure><img src="https://1613591589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5CSDwdOaYoOAGYNiRqgl%2Fuploads%2Fgit-blob-a3b5ce883de6dd9cab56b9aa05e163791f880eb6%2F88de6be2f1613c4e8985cfd5e9ca873afa7b7df2.png?alt=media" alt="Add wildcard patterns to SonarQube for Visual Studio to exclude files from a local analysis. Locally defined file exclusions are ignored when in connected mode." width="563"><figcaption></figcaption></figure></div>

The local file exclusions and exclusion patterns use the `sonarlint.analysisExcludesStandalone` property to update the same setting.json file where you enable and disable rules (see the [#disabling-a-rule](https://docs.sonarsource.com/sonarqube-for-visual-studio/rules#disabling-a-rule "mention") article). To edit this json file directly, navigate to the **SonarQube** > **Options** > **General** window and select **Edit Settings**, which will open your settings.json file in Visual Studio. As when using the UI, exclusions for C# and VB.NET files are applied on the next analysis.

### settings.json file format and location <a href="#settingsjson-file-format-and-location" id="settingsjson-file-format-and-location"></a>

The settings.json file is stored in your user’s roaming profile `%APPDATA%\SonarLint for Visual Studio`.

See this example as a format sample of your settings.json file. It changes the parameters on a few rules, and at the end, excludes any files matching `*Interface.cs` plus everything in the `org/sonar/*` directory.

```json
{
 "sonarlint.rules": {
   "c:S1135": {
     "level": "On"
   },
   "cpp:S1199": {
     "level": "Off"
   },
   "cpp:SingleGotoOrBreakPerIteration": {
     "level": "On",
     "parameters": {
       "maxNumberOfTerminationStatements": "1"
     }
   },
   "javascript:S1135": {
     "level": "Off"
   },
   "typescript:S1854": {
     "level": "On"
   }
 }
  "sonarlint.analysisExcludesStandalone": "**/*Interface.cs,org/sonar/*"
}
```

## Defining solution exclusions <a href="#defining-solution-exclusions" id="defining-solution-exclusions"></a>

Navigate to **Extensions** > **SonarQube** > **Solution Settings** > **File Exclusions** and select **Add** to configure the file names and/or wild card patterns you want to exclude from the analysis. Any acceptable wildcard pattern can be used. Note that the values you define here will override the global values defined in your File exclusions. Remember that when running SonarQube for Visual Studio in [connected-mode](https://docs.sonarsource.com/sonarqube-for-visual-studio/connect-your-ide/connected-mode "mention"), all locally defined exclusion values will be ignored.

Check the [scan-my-project](https://docs.sonarsource.com/sonarqube-for-visual-studio/using/scan-my-project "mention") page for information about specifying additional analyzer properties.

## Wildcard patterns <a href="#using-wildcards" id="using-wildcards"></a>

The recognized path-matching patterns are case-sensitive and defined using the following wildcards:

* `*` Match zero or more characters (not including the directory delimiter, `/` ).
* `**` Match zero or more directory segments or files within the path.
* `?` Match a single character (not including the directory delimiter, `/` ).

**Wildcard examples**

* The pattern `**/*.css`
  * matches `anyDirectory/anyFile.css`
  * doesn’t match `org/sonar.api/MyBean.java`
* The pattern `**/*Bean.java`
  * matches `org/sonar.api/MyBean.java`
  * doesn’t match `org/sonar.api/mybean.java` or `org/sonar/util/MyDTO.java`
* The pattern `**/*Bean?.java`
  * matches `org/sonar/util/MyOtherBean1.java`
  * doesn’t match `org/sonar/util/MyOtherBean.java`
* The pattern `org/sonar/*`
  * matches `org/sonar/MyClass.java`
  * doesn’t match `org/sonar/util/MyClassUtil.java`
* The pattern `org/sonar/**/*` is equivalent to `org/sonar/**` and
  * matches `org/sonar/anyDirectory/anyFile`
  * matches `org/sonar/MyClass.java`
  * doesn’t match `org/radar/MyClass.java`

The use of `?` to match a single character is available in SonarQube for Visual Studio.

{% hint style="info" %}
Note that when running in connected mode, only the file exclusions defined on the server are respected.

When running a local analysis for Security hotspots, which requires using connected mode, it is possible to omit some folders from the project analysis. Because you are in [setup](https://docs.sonarsource.com/sonarqube-for-visual-studio/connect-your-ide/setup "mention"), a requirement to detect security hotspots in SonarQube for IDE, exclusions defined in Visual Studio will be ignored.

Check the documentation on [security-hotspots](https://docs.sonarsource.com/sonarqube-for-visual-studio/using/security-hotspots "mention") for those details.
{% endhint %}

## Special exclusion cases <a href="#special-exclusion-cases" id="special-exclusion-cases"></a>

**.cshtml or .razor files**

To exclude .cshtml or .razor files in SonarQube for Visual Studio, you must add a wildcard to cover a postfix to the file extension. For example, to exclude all .cshtml files, use the `*cshtml*` pattern; for .razor files, use `*razor*`.

Additionally, adding the analysis property `sonar.cs.analyzeRazorCode` with the value `false` will completely disable the analysis for all Razor files.

## Retrieving exclusions from the server <a href="#retrieving-exclusions-from-the-server" id="retrieving-exclusions-from-the-server"></a>

<details>

<summary>File exclusions</summary>

When running in connected mode, SonarQube for Visual Studio will fetch file exclusions from SonarQube Server or SonarQube Cloud when you bind a project. These settings are saved to a file named sonar.settings.json.

Note that in SonarLint for Visual Studio 7.0, the settings file was moved outside of the solution directory; please check the **Legacy Connected Mode** article on the [previous-versions](https://docs.sonarsource.com/sonarqube-for-visual-studio/resources/previous-versions "mention") page for information about the settings file in versions 6.16 and older.

For more information about how SonarQube for Visual Studio settings are handled by the server, look at the server documentation on setting your analysis scope:

* See the [Setting analysis scope](https://app.gitbook.com/s/LWhbesChsC4Yd1BbhHhS/project-administration/adjusting-analysis/setting-analysis-scope "mention") pages in SonarQube Server.
* See the [Analysis scope](https://app.gitbook.com/s/B4UT2GNiZKjtxFtcFAL7/managing-your-projects/project-analysis/setting-analysis-scope "mention") pages in SonarQube Cloud.
* See the [Setting analysis scope](https://app.gitbook.com/s/bqrfLGeD0Y9vE5l9Le42/project-administration/adjusting-analysis/setting-analysis-scope "mention") pages in SonarQube Community Build.

<div align="left"><img src="https://1613591589-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5CSDwdOaYoOAGYNiRqgl%2Fuploads%2Fgit-blob-52cfd298b62ac53715981cdc42502a8902a0dbea%2F6ca7f186aaddd29c0bf0bc57ea5ebc6f619f191b.png?alt=media" alt="When file exclusions are defined on the server, they are respected by SonarQube for IDE when running in connected mode."></div>

Known limitations for file exclusions:

* Supported Languages: C# & VB (.NET support in SonarLint v6.15+), C, C++, CSS, JavaScript, TypeScript, and Secrets.
* Patterns should start with `**/`
* Multicriteria and Test exclusions are not supported. SonarQube for Visual Studio only supports Global Source File Exclusions, Source File Exclusions, and Source File Inclusions when setting the analysis scope. For more information about file inclusion and exclusion, see the pages about file inclusion and exclusion in the
  * [Excluding based on path-matching patterns](https://app.gitbook.com/s/LWhbesChsC4Yd1BbhHhS/project-administration/adjusting-analysis/setting-analysis-scope/excluding-files-based-on-patterns "mention") in SonarQube Server
  * [Excluding based on path-matching patterns](https://app.gitbook.com/s/B4UT2GNiZKjtxFtcFAL7/managing-your-projects/project-analysis/setting-analysis-scope/excluding-files-based-on-patterns "mention") in SonarQube Cloud
  * [Excluding based on path-matching patterns](https://app.gitbook.com/s/bqrfLGeD0Y9vE5l9Le42/project-administration/adjusting-analysis/setting-analysis-scope/excluding-files-based-on-patterns "mention") in SonarQube Community Build

</details>
