Search code examples
c#visual-studiocmakestylecop

How can you apply StyleCop settings for all projects using CMake?


I have many C# projects in my Visual Studio solution, and I want to change to StyleCop settings for all of them. How can I use CMake to ensure that when others pull my code and work with my solution, they can use the same StyleCop rules that I have set up, and have those rules apply to the entire solution?


Solution

  • To ensure StyleCop settings apply to all of the projects in the solution, you have to place the Settings.StyleCop file in the root directory of the solution, as suggested here. Once you've finalized your StyleCop rules in the settings file, you can put the settings file in your source, for example here input/Settings.StyleCop. In your top-level CMakeLists.txt file, you can tell CMake to copy the settings file into your build directory as a sibling of the generated solution file:

    configure_file(input/Settings.StyleCop Settings.StyleCop COPYONLY)