GCop is a set up code analysis rules for improving C# code.
First of all make sure you have installed visual studio 2017 version 15.5.5 or a newer one.
- Open any solution in Visual Studio
- Right click on the solution, and select Manage NuGet Packages...
- At the top right corner of the window, click on the ⚙ icon.
- Click the ➕ icon
- Set Name to GCop
- Set source to http://nuget.gcop.co/nuget
- Click OK
Note : You need to do this only once.
- Open the Manage NuGet Packages... window for your solution.
- Next to the ⚙ icon, change the drop-down list to All
- If your project has a reference to M#, Zebble or Olive nuget packages, then install
GCop.All.Geeks
- Otherwise, install select
GCop.All.Common
- Install it on all projects in your solution (or the ones that you need analysed)
Note : You need to do this once for each project / solution.
- After adding GCop to a project, build that project in Visual Studio in the normal way.
- Open the Error List window
- Ensure Errors, Warnings and Messages tabs are all selected
- Ensure the last drop down is selected as Build + IntelliSense
- Make sure you see items in the Error List window whose Code starts with GCop.
- If you don't see any GCop warnings, right click on each project and select Properties > Code Analysis and ensure Enable Code Analysis on Build is ticked.
- In order to get rid of
Microsoft.CodeAnalysis
warnings, You have to update your codeDOM. - For getting ride of NETStandard warnings , you need to install the
NETStandard.Library
NuGet into the website project and then add thenetstandard.dll
as an analyzer. - For adding a dll as analyzer you can right click on the website project , go to Add > Analyzer > then find the netstandrd all in the installed Package folder.
If you disagree with any of the GCop rules, or if you believe they are not applicable to your project, you can Escape the Cop, i.e. disable it, using any of the following methods.
Unfortunately Visual Studio doesn't allow you to disable analysis rules at the solution level. But you can disable them for every project in your solution.
- Right click on the project and select Properties
- Select the Build tab
- Update the Suppress warnings field to include the warning codes you want to disable.
- Separate multiple warning codes with a semicolon, e.g:
GCop316; GCop140; GCop179
- Separate multiple warning codes with a semicolon, e.g:
You can disable GCop for specific C# classes by adding the [EscapeGCop]
attribute on top of it. You can optionally provide a reason description as well. This is particularly useful for auto-generated code.
For example:
[EscapeGCop("This class is auto generated.")]
public class MyClass
{
...
}
You can disable GCop for specific methods by adding the [EscapeGCop]
attribute on top of it. For example:
...
[EscapeGCop("It's not applicable because ....")]
public void SomeMethod()
{
...
}
...
You should use it in the following scenarios:
- In cases GCop is giving you a false alarm
- Where a rule is not applicable in a particular scenario in your opinion.
As this documentation is a kind of Open-Doc, contributions are welcome. We are currently focused on documenting GCop errors. Feel free to review, contribute and pull request to this documentation. we'll review your PR as soon as we can and we will do the merge if everything was just fine. If there was any kind of issues, please post it in the issues section. Make sure that you follow our writing styles.
This project is maintained and supported by the GeeksLtd.
See also the list of contributors who participated in this project.