Add Ruleset to Solution Visual Studio

Unfortunately, Visual Studio 2017 does not support rule set file configuration tools for .NET Core and .NET Standard projects. However, you can still do this manually by creating a custom rule set and having the csproj use it. You first create the rule set file. Once you have the rule set file, edit the csproj and add an a that points to the desired rule set file. The path can be a full path or a relative path to the project file. Here`s an example: Place the rule set file in a directory of your choice. For example, in the same directory as your solution file. After you define the custom rule set in the directory that you want, right-click the solution in Visual Studio, select Add >Existent item, and then select the custom rule set. After you configure the rules as you want, save the file. When the rule set is saved, Visual Studio creates a rule set file in the project directory, adds it to the project, and modifies the .csproj file to add a property to the section that references the custom rule set that you just created. Note that the rule set tools in Visual Studio 2017 do not support .NET Core and .NET Standard projects. That doesn`t mean you can`t have a solution-wide set of rules for your projects. This only means that you need to manually add your solution-wide rule set to your .NET Core and .NET Standard projects by following the instructions here.

If the projects in your solution have a hierarchical structure, which means that they reference each other and have a common and most abstract basis rooted in the structure similar to the following: @fiksen99 Please comment if this still poses a problem for you, but I believe that if you right-click on the project node instead of the project node, They should be ready to go. @fiksen99 I think you right-clicked on the solution and not on the project. Can you try that? In Visual Studio, you can choose from a list of code analysis rule sets to apply to a managed code project. By default, the Microsoft Recommended Minimum Rule Set is selected, but you can apply a different set of rules if necessary. Rule sets can be applied to one or more projects in a solution. @stevenbrix @gewarren We plan to discontinue this site soon. You can read the suggested reasoning and approaches in developercommunity.visualstudio.com/content/problem/317861/code-analysis-settings-doesn`t-load.html Select Save As, type a name for the RULESET file, and then choose Save. This script I found at John Robbins is excellent: www.wintellect.com/batch-updating-changing-visual-studio-projects-with-powershell/ Now that you`ve created the custom rule set and added it to the solution, go to the solution`s properties and, under General Properties, select the Code Analysis Settings tab. This displays all projects for which rule sets can be configured by using Visual Studio tools. Simply select the rule set you created from the drop-down list. Therefore, by default, StyleCop.Analyzers is enabled only in the project in which you explicitly reference the package. But in almost every codebase I`ve been involved in, applying StyleCode rules in all projects in the solution was desirable (almost all except for projects with automatically generated code, such as EF migrations).

If you change all package reference metadata to none, the formatting rules are propagated to all projects that depend on them. Make sure that the Name property of the custom rule set uniquely identifies the rule set file, because a solution can contain many rule set files, and as we will see, this name is used by Visual Studio tools so that you can choose the rule set that you want to apply to each project. CA0063: Unable to load the rule set file `[your].ruleset` or one of the dependent rule set files. The file does not conform to the schema of the rule set. If you want to create a custom rule set by using Visual Studio tools, this file is added to the project for which you created the custom rule set. Because this set of rules is applied to the solution, I recommend that you copy the file from the project directory and add it in the same direction as your solution. Do not leave the file in the project directory after copying it to the solution directory. There you go. The next time you run or build the project in Visual Studio (you may need to close/reopen the solution when it is open), these rules should apply. @jinujoseph Markup – Do we have an internal work item to track the removal of the code analysis settings page at the solution level? You can change the default behavior of the scanners available in your solution. Suppose you have a nuget installed with a lot of useful parsers, but there are some that you want to disable, or maybe there is a project where you want to enable the X parser and another project where the same scanner needs to be disabled.

How to deal with it? @mavasani Would it be a good idea to add a link to this page in the Code Analysis tab of a solution`s properties? @stevenbrix For clarity only: Are you referring to the message on the Code Analysis Settings tab for solution properties and suggesting that users open the project properties instead? To specify all the projects in the solution, choose Shift and the list of projects. If you don`t agree to create your own from scratch, I recommend that you create a .NET Framework project, add the desired parser, and then follow the steps mentioned earlier. After Visual Studio generates the rule set file, edit it to make sure that it contains only those rules that are important to you. The new RULESET file opens in the rule set editor. By default, all managed projects in a solution are assigned the Microsoft Minimum Recommended Rules set of code analysis rules.