Install StyleCop

Overview

Install StyleCop

These are instructions for how to install StyleCop and our custom rule set for the Programming classes. Most if not all of the start code will have this set up, but any time you set up a new Project you will need to take these steps to add StyleCop to that project.

Work through the stories in order. Use the acceptance criteria to check each feature, and complete the nested tasks using the specified names, values, and scenarios.

Integrate StyleCop with the project
Acceptance Criteria
Acceptance criteria
  • The StyleCop folder is beside the solution, and packages.config is in the project folder.
  • The project and assembly configuration contain the required entries.
  • NuGet packages are restored and the required DLLs are unblocked.
Instructions
1.Download the zip file below and extract it.

StyleCop.zip

StyleCop.zip
A Download the zip file below and extract it.
2.Move the folder to the same level as your .sln
Place Folder for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Place Folder
A Move the folder to the same level as your .sln
3.In the StyleCop folder, cut the packages.config file and paste it in the project folder.
Paste config file for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Paste config file
A In the StyleCop folder, cut the packages.config file and paste it in the project folder.
4.Edit the .csproj file
A Navigate into the project you need to add StyleCop to.

In this case it's ZooScenario, but in OOP we will be adding new projects that need to be updated with StyleCop settings.

B Right click the project's .csproj file and open it in a text editor.
Open with Text Editor for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Open with Text Editor
C After the third closing Property tag, copy and paste the text below.
<ItemGroup>
<None Include="packages.config" />
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.118\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.118\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
<AdditionalFiles Include="..\StyleCop\ProgrammingConcepts.json" />
</ItemGroup>
<PropertyGroup>
<DocumentationFile>..\StyleCop\$(AssemblyName).xml</DocumentationFile>
<CodeAnalysisRuleSet>..\StyleCop\ProgrammingConcepts.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
4C - PasteCode for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
4C - PasteCode
D Save the .csproj file and close.
5.Edit the AssemblyInfo.cs
A In the project folder, navigate into the Properties folder.
B Right click the AssemblyInfo.cs file and open it in a text editor.
Open AssemblyInfo for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Open AssemblyInfo
C Paste the text below on the top line.
#pragma warning disable SA1005, SA1009, SA1111, SA1507, SA1512, SA1515#pragma warning disable SA1005, SA1009, SA1111, SA1507, SA1512, SA1515
Paste First Assembly for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Paste First Assembly
D Paste the text below at the bottom.
#pragma warning restore SA1005, SA1009, SA1111, SA1507, SA1512, SA1515#pragma warning restore SA1005, SA1009, SA1111, SA1507, SA1512, SA1515
Paste Last Assembly for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Paste Last Assembly
E Save and close the file.
6.Open Visual Studio, right click the Solution and click 'Restore NuGet packages'.
Restore NuGet Packages for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Restore NuGet Packages
A Open Visual Studio, right click the Solution and click 'Restore NuGet packages'.
7.Unblock the StyleCop dll
A When you open the sln file in Visual Studio, you might see this warning:
blocked analyzers for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
blocked analyzers
B Close the solution. Go to your solution folder and in the search bar, type in "stylecop.analyzers.dll"
C Right click on the StyleCop.Analyzers.dll file and click on properties
D Unblock the file and apply the changes
unblockdll for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
unblockdll
E Open the solution in Visual Studio again. The warning should be gone.
Verify the editing and analysis settings
Acceptance Criteria
Acceptance criteria
  • The requested editor settings are applied.
  • The test produces the expected analyzer feedback.
  • The intentional violation is corrected and the project builds cleanly.
Instructions
8.Configure the Visual Studio Text Editor
A Click Tools ---> Options in the file menu.
B Expand Text Editor in the left window.
C Expand C# in the left window.
D Select Advanced in the left window.
E Check the box for Enable full solution analysis.
F Check the box for Place 'System' directives first when sorting usings.
Customize Text Editor for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Customize Text Editor
9.Test StyleCop

In this step there will be a simple summary tag missing to demonstrate.

A Open the .sln file.
B Build your solution/project.
C Navigate to your Error List window and you will see any StyleCop issues raised as Warnings as well as green lines on the problem.

Make sure the Build + IntelliSense is selected from the drop down.

Error List for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Error List
D When the issue is fixed, the Warning should go away immediately.
Fixed Warning for Install StyleCop. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Fixed Warning
E Rebuild the entire solution to ensure no warnings are present.
Completion review
10.Review the feature acceptance criteria
A Confirm the required results

Return to each story and verify its acceptance criteria. Preserve the submission format and destination stated in the activity; a reading, setup guide, lab, video demonstration, and oral final may require different evidence.

Integrate StyleCop with the project Verify the editing and analysis settings