SlideShare a Scribd company logo
StyleCop
Breaking down the barriers to entry

Gary Ewan Park
gep13@gep13.co.uk
Twitter: @gep13
Blog: http://www.gep13.co.uk/blog
Agenda
•
•
•
•
•
•
•
•

What is StyleCop?
Visual Studio Integration
MSBuild Integration
Using a Custom Task
StyleCop Compliance
Extending StyleCop
Working with “Legacy” Applications
Additional Tooling Support
Source Code

http://gep13.me/StyleCopDemos
What is StyleCop?
A Definition…
“StyleCop is an open source static code analysis tool
from Microsoft that checks C# code for conformance to
StyleCop's recommended coding styles and a subset of
Microsoft's .NET Framework Design Guidelines. StyleCop
analyzes the source code, allowing it to enforce a different set
of rules from FxCop.” *
Reference
 http://stylecop.codeplex.com/

* http://en.wikipedia.org/wiki/StyleCop
What does that mean?
• StyleCop is a “plugin” for Visual Studio 2008, 2010, and VS
11 Preview (and in a way, 2005* and Express)
• It provides 162 rules over 7 categories of “style”

* http://gep13.me/ie1T0V
Visual Studio
Integration
Visual Studio Integration
Demo 1

Visual Studio Integration
Using StyleCop on a New Project
MSBuild Integration
This gets installed by default…
During the installation
you have the option
to install MSBuild files.
These files will be
required if you want to
integrate StyleCop
analysis with the Visual
Studio build process or
a Continuous
Integration Server.
MSBuild Integration – Visual Studio
To add StyleCop as part of the “Build” process in Visual Studio
follow these steps:
1. Use the StyleCop.MSBuild Nuget package to install the
necessary files and make file edits.
2. This edits the project file to include:

3. Add the following property in the project file to force all
warnings to be treated as errors:
Demo 2

MSBuild Integration
Including StyleCop Analysis as part of the
Build Process
Using a Custom
Task
MSBuild Integration – Custom Task
• StyleCop also includes a MSBuild task that can be used to
create a custom build step

• Manning Publications – Continuous Integration in .NET
• http://gep13.me/MuNEL9
Demo 3

Using a Custom Task
Running StyleCop Analysis as a custom task
with MSBuild and TeamCity
StyleCop
Compliance
Visual Studio Templates
During the installation
you have the option to
install a new set of
Visual Studio
Templates, which will
already by StyleCop
“compliant”
Going further with more templates…
• Use StyleCop compliant code snippets
• http://vssnippets.codeplex.com/
• Use StyleCop compliant project/item templates
• http://vstemplates.codeplex.com/
Talk to your Team
• Get Buy-In from your Team Members
• Only enable the StyleCop rules that you want to
follow
• Have a team meeting to decide
Demo 4

StyleCop Compliance
Using StyleCop Compliant Project/Item
Templates and Code Snippets
Extending StyleCop
Add More StyleCop Rules
• There are a number of projects that are extending the builtin StyleCop rules:
 StyleCop+
o http://stylecopplus.codeplex.com/
 JSL StyleCop
o http://jslstylecop.codeplex.com/
Create your own Custom StyleCop Rule
1.
2.
3.
4.

5.
6.

Create a .Net Framework 3.5 Class Library Project in
Visual Studio
Add a reference to StyleCop.dll and StyleCop.Csharp.dll
Create your analyzer class that inherits from
SourceAnalyzer
Add an XML file with the same name as the analyzer
class. Set the properties of the XML file to be an
Embedded Resource and not copy to the output directory
Override the AnalyzeDocument method
You are ready to write your own analysis code

• http://gep13.me/JIn0xL
StyleCop Contrib
This CodePlex Project started out life as another Custom
StyleCop Rule Library, however, now it is a Unit Testing
Framework for Custom StyleCop Rules

http://stylecopcontrib.codeplex.com
Allows you to quickly begin testing your Rules, without the
need to debug multiple instances of Visual Studio
Demo 5

Extending StyleCop
Create a Custom StyleCop Rule and then test
it with Unit Tests
Working with
“Legacy”
Applications
Using StyleCop in an Existing Project
• Turn off analysis for
generated code
• Surround code in a
region with the text „generated code‟ within the title
• Turn off StyleCop Analysis for a particular file using
SourceFileList in Settings.StyleCop file
• Turn off StyleCop Analysis for an entire project using
Settings.StyleCop file
Demo 6

Working with “Legacy” Applications
Turning StyleCop off for an existing large
project using Settings file
Additional Tooling
Support
Refactoring StyleCop Rules
• There are plugins available for both CodeRush and
ReSharper to help refactor code to be StyleCop Compliant
• StyleCop For ReSharper
 Now included as part of the core StyleCop installation
 Automatically fixes 128 StyleCop issues during
ReSharper “CleanUp Code…”
• Style Ninja for CodeRush
 http://code.google.com/p/dxcorecommunityplugins/wiki/
CR_StyleNinja
 Fixes 23 StyleCop Issues
ReSharper Integration
During the installation
you have the option
to install ReSharper
Integration files, these
will be required if you
want to be able to
analyse and correct
StyleCop warnings
using ReSharper
Refactorings.
Demo 7

Additional Tooling Support
Using ReSharper to improve StyleCop
Compliance
Questions?

Feel free to email me any additional
questions at
gep13@gep13.co.uk

More Related Content

What's hot

Develop Maintainable Apps - edUiConf
Develop Maintainable Apps - edUiConfDevelop Maintainable Apps - edUiConf
Develop Maintainable Apps - edUiConf
Annyce Davis
 
Testlink Test Management with Teamforge
Testlink Test Management with TeamforgeTestlink Test Management with Teamforge
Testlink Test Management with Teamforge
CollabNet
 
Introduction to testlink
Introduction to testlinkIntroduction to testlink
Introduction to testlinkSumara Khan
 
Automated Testing Environment by Bugzilla, Testopia and Jenkins
Automated Testing Environment by Bugzilla, Testopia and JenkinsAutomated Testing Environment by Bugzilla, Testopia and Jenkins
Automated Testing Environment by Bugzilla, Testopia and Jenkins
walkerchang
 
Create Drupal patches with Aptana
Create Drupal patches with AptanaCreate Drupal patches with Aptana
Create Drupal patches with Aptana
Roy Scholten
 
Unit & integration testing
Unit & integration testingUnit & integration testing
Unit & integration testing
Pavlo Hodysh
 
ATAGTR2017 Machine Learning telepathy for Shift Right approach of testing
ATAGTR2017 Machine Learning telepathy for Shift Right approach of testingATAGTR2017 Machine Learning telepathy for Shift Right approach of testing
ATAGTR2017 Machine Learning telepathy for Shift Right approach of testing
Agile Testing Alliance
 
Btd presentation-2011
Btd presentation-2011Btd presentation-2011
Btd presentation-2011
kinow
 
Continuous delivery
Continuous deliveryContinuous delivery
Continuous delivery
Alexandru Bolboaca
 
HKG15-411: Browser Testing Framework for LHG
HKG15-411: Browser Testing Framework for LHGHKG15-411: Browser Testing Framework for LHG
HKG15-411: Browser Testing Framework for LHG
Linaro
 
Utility of Test Coverage Metrics in TDD
Utility of Test Coverage Metrics in TDDUtility of Test Coverage Metrics in TDD
Utility of Test Coverage Metrics in TDD
XP Conference India
 
Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platform
Chamil Madusanka
 
TestLink introduction
TestLink introductionTestLink introduction
TestLink introduction
David Ionut
 
vREST Test Automation
vREST Test AutomationvREST Test Automation
vREST Test Automation
Pankaj Jangid
 
SpecFlow for Agile Teams
SpecFlow for Agile TeamsSpecFlow for Agile Teams
SpecFlow for Agile Teams
Alejandro Ramirez
 
Test Presentation
Test PresentationTest Presentation
Test Presentation
setitesuk
 
Keyword Driven Testing using TestComplete
Keyword Driven Testing using TestCompleteKeyword Driven Testing using TestComplete
Keyword Driven Testing using TestComplete
srivinayak
 
Defect life cycle and Defect Status Life Cycle
Defect life cycle and Defect Status Life CycleDefect life cycle and Defect Status Life Cycle
Defect life cycle and Defect Status Life Cycle
pavansmiles
 
Introduction to Continuous integration
Introduction to Continuous integrationIntroduction to Continuous integration
Introduction to Continuous integration
liortal53
 
Android tdd
Android tddAndroid tdd
Android tdd
Nhan Cao
 

What's hot (20)

Develop Maintainable Apps - edUiConf
Develop Maintainable Apps - edUiConfDevelop Maintainable Apps - edUiConf
Develop Maintainable Apps - edUiConf
 
Testlink Test Management with Teamforge
Testlink Test Management with TeamforgeTestlink Test Management with Teamforge
Testlink Test Management with Teamforge
 
Introduction to testlink
Introduction to testlinkIntroduction to testlink
Introduction to testlink
 
Automated Testing Environment by Bugzilla, Testopia and Jenkins
Automated Testing Environment by Bugzilla, Testopia and JenkinsAutomated Testing Environment by Bugzilla, Testopia and Jenkins
Automated Testing Environment by Bugzilla, Testopia and Jenkins
 
Create Drupal patches with Aptana
Create Drupal patches with AptanaCreate Drupal patches with Aptana
Create Drupal patches with Aptana
 
Unit & integration testing
Unit & integration testingUnit & integration testing
Unit & integration testing
 
ATAGTR2017 Machine Learning telepathy for Shift Right approach of testing
ATAGTR2017 Machine Learning telepathy for Shift Right approach of testingATAGTR2017 Machine Learning telepathy for Shift Right approach of testing
ATAGTR2017 Machine Learning telepathy for Shift Right approach of testing
 
Btd presentation-2011
Btd presentation-2011Btd presentation-2011
Btd presentation-2011
 
Continuous delivery
Continuous deliveryContinuous delivery
Continuous delivery
 
HKG15-411: Browser Testing Framework for LHG
HKG15-411: Browser Testing Framework for LHGHKG15-411: Browser Testing Framework for LHG
HKG15-411: Browser Testing Framework for LHG
 
Utility of Test Coverage Metrics in TDD
Utility of Test Coverage Metrics in TDDUtility of Test Coverage Metrics in TDD
Utility of Test Coverage Metrics in TDD
 
Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platform
 
TestLink introduction
TestLink introductionTestLink introduction
TestLink introduction
 
vREST Test Automation
vREST Test AutomationvREST Test Automation
vREST Test Automation
 
SpecFlow for Agile Teams
SpecFlow for Agile TeamsSpecFlow for Agile Teams
SpecFlow for Agile Teams
 
Test Presentation
Test PresentationTest Presentation
Test Presentation
 
Keyword Driven Testing using TestComplete
Keyword Driven Testing using TestCompleteKeyword Driven Testing using TestComplete
Keyword Driven Testing using TestComplete
 
Defect life cycle and Defect Status Life Cycle
Defect life cycle and Defect Status Life CycleDefect life cycle and Defect Status Life Cycle
Defect life cycle and Defect Status Life Cycle
 
Introduction to Continuous integration
Introduction to Continuous integrationIntroduction to Continuous integration
Introduction to Continuous integration
 
Android tdd
Android tddAndroid tdd
Android tdd
 

Similar to StyleCop breaking down the barriers to entry

Sitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helixSitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helix
Peter Nazarov
 
Static Analysis Tools for C# Demo
Static Analysis Tools for C# DemoStatic Analysis Tools for C# Demo
Static Analysis Tools for C# Demo
Adriano Ueda
 
Building iOS App Project & Architecture
Building iOS App Project & ArchitectureBuilding iOS App Project & Architecture
Building iOS App Project & Architecture
Massimo Oliviero
 
Accelerating time to delivery - Modern tools for COBOL development
Accelerating time to delivery - Modern tools for COBOL developmentAccelerating time to delivery - Modern tools for COBOL development
Accelerating time to delivery - Modern tools for COBOL development
Micro Focus
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
ssuser9e7c64
 
Build your android app with gradle
Build your android app with gradleBuild your android app with gradle
Build your android app with gradle
Swain Loda
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
Amr Abd El Latief
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
Malisa Ncube
 
Codingstandards matiar
Codingstandards matiarCodingstandards matiar
Codingstandards matiarMatiar Rahman
 
44 Slides About 22 Modules
44 Slides About 22 Modules44 Slides About 22 Modules
44 Slides About 22 Modules
heyrocker
 
New life inside monolithic application
New life inside monolithic applicationNew life inside monolithic application
New life inside monolithic application
Taras Matyashovsky
 
Building reusable websites on Drupal 8: lessons learned from transforming red...
Building reusable websites on Drupal 8: lessons learned from transforming red...Building reusable websites on Drupal 8: lessons learned from transforming red...
Building reusable websites on Drupal 8: lessons learned from transforming red...
Peter Vanhee
 
Accelerating time to delivery modern tools for cobol development
Accelerating time to delivery modern tools for cobol developmentAccelerating time to delivery modern tools for cobol development
Accelerating time to delivery modern tools for cobol development
Micro Focus
 
Working with PowerShell, Visual Studio Code and Github for the reluctant IT Pro
Working with PowerShell, Visual Studio Code and Github for the reluctant IT ProWorking with PowerShell, Visual Studio Code and Github for the reluctant IT Pro
Working with PowerShell, Visual Studio Code and Github for the reluctant IT Pro
BIWUG
 
Mastering azure devOps - Dot Net Tricks
Mastering azure devOps - Dot Net TricksMastering azure devOps - Dot Net Tricks
Mastering azure devOps - Dot Net Tricks
Gaurav Singh
 
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
Michael Miles
 
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Vadym Kazulkin
 
Joomla! theming
Joomla! themingJoomla! theming
Joomla! theming
Russell Searle
 
Releasing High Quality PHP Packages - ConFoo Montreal 2019
Releasing High Quality PHP Packages - ConFoo Montreal 2019Releasing High Quality PHP Packages - ConFoo Montreal 2019
Releasing High Quality PHP Packages - ConFoo Montreal 2019
Colin O'Dell
 
Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021
Colin O'Dell
 

Similar to StyleCop breaking down the barriers to entry (20)

Sitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helixSitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helix
 
Static Analysis Tools for C# Demo
Static Analysis Tools for C# DemoStatic Analysis Tools for C# Demo
Static Analysis Tools for C# Demo
 
Building iOS App Project & Architecture
Building iOS App Project & ArchitectureBuilding iOS App Project & Architecture
Building iOS App Project & Architecture
 
Accelerating time to delivery - Modern tools for COBOL development
Accelerating time to delivery - Modern tools for COBOL developmentAccelerating time to delivery - Modern tools for COBOL development
Accelerating time to delivery - Modern tools for COBOL development
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Build your android app with gradle
Build your android app with gradleBuild your android app with gradle
Build your android app with gradle
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
 
Codingstandards matiar
Codingstandards matiarCodingstandards matiar
Codingstandards matiar
 
44 Slides About 22 Modules
44 Slides About 22 Modules44 Slides About 22 Modules
44 Slides About 22 Modules
 
New life inside monolithic application
New life inside monolithic applicationNew life inside monolithic application
New life inside monolithic application
 
Building reusable websites on Drupal 8: lessons learned from transforming red...
Building reusable websites on Drupal 8: lessons learned from transforming red...Building reusable websites on Drupal 8: lessons learned from transforming red...
Building reusable websites on Drupal 8: lessons learned from transforming red...
 
Accelerating time to delivery modern tools for cobol development
Accelerating time to delivery modern tools for cobol developmentAccelerating time to delivery modern tools for cobol development
Accelerating time to delivery modern tools for cobol development
 
Working with PowerShell, Visual Studio Code and Github for the reluctant IT Pro
Working with PowerShell, Visual Studio Code and Github for the reluctant IT ProWorking with PowerShell, Visual Studio Code and Github for the reluctant IT Pro
Working with PowerShell, Visual Studio Code and Github for the reluctant IT Pro
 
Mastering azure devOps - Dot Net Tricks
Mastering azure devOps - Dot Net TricksMastering azure devOps - Dot Net Tricks
Mastering azure devOps - Dot Net Tricks
 
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
 
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
 
Joomla! theming
Joomla! themingJoomla! theming
Joomla! theming
 
Releasing High Quality PHP Packages - ConFoo Montreal 2019
Releasing High Quality PHP Packages - ConFoo Montreal 2019Releasing High Quality PHP Packages - ConFoo Montreal 2019
Releasing High Quality PHP Packages - ConFoo Montreal 2019
 
Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021
 

More from Gary Park

A Piece of Cake - DDD North
A Piece of Cake - DDD NorthA Piece of Cake - DDD North
A Piece of Cake - DDD North
Gary Park
 
A Piece of Cake - DDD11 - Reading
A Piece of Cake - DDD11 - ReadingA Piece of Cake - DDD11 - Reading
A Piece of Cake - DDD11 - Reading
Gary Park
 
A Piece of Cake - NDC Oslo 2016
A Piece of Cake - NDC Oslo 2016A Piece of Cake - NDC Oslo 2016
A Piece of Cake - NDC Oslo 2016
Gary Park
 
Having your cake, and eating it too! - DDDScotland
Having your cake, and eating it too! - DDDScotlandHaving your cake, and eating it too! - DDDScotland
Having your cake, and eating it too! - DDDScotland
Gary Park
 
Having your cake, and eating it too!
Having your cake, and eating it too!Having your cake, and eating it too!
Having your cake, and eating it too!
Gary Park
 
Semantic Versioning with GitVersion - Take 2
Semantic Versioning with GitVersion - Take 2Semantic Versioning with GitVersion - Take 2
Semantic Versioning with GitVersion - Take 2
Gary Park
 
Semantic Versioning with GitVersion
Semantic Versioning with GitVersionSemantic Versioning with GitVersion
Semantic Versioning with GitVersion
Gary Park
 
Getting started with caliburn.micro and windows phone 7
Getting started with caliburn.micro and windows phone 7Getting started with caliburn.micro and windows phone 7
Getting started with caliburn.micro and windows phone 7
Gary Park
 
Mmmm, chocolatey goodness!
Mmmm, chocolatey goodness!Mmmm, chocolatey goodness!
Mmmm, chocolatey goodness!
Gary Park
 
Continuous integration 101
Continuous integration 101Continuous integration 101
Continuous integration 101
Gary Park
 

More from Gary Park (10)

A Piece of Cake - DDD North
A Piece of Cake - DDD NorthA Piece of Cake - DDD North
A Piece of Cake - DDD North
 
A Piece of Cake - DDD11 - Reading
A Piece of Cake - DDD11 - ReadingA Piece of Cake - DDD11 - Reading
A Piece of Cake - DDD11 - Reading
 
A Piece of Cake - NDC Oslo 2016
A Piece of Cake - NDC Oslo 2016A Piece of Cake - NDC Oslo 2016
A Piece of Cake - NDC Oslo 2016
 
Having your cake, and eating it too! - DDDScotland
Having your cake, and eating it too! - DDDScotlandHaving your cake, and eating it too! - DDDScotland
Having your cake, and eating it too! - DDDScotland
 
Having your cake, and eating it too!
Having your cake, and eating it too!Having your cake, and eating it too!
Having your cake, and eating it too!
 
Semantic Versioning with GitVersion - Take 2
Semantic Versioning with GitVersion - Take 2Semantic Versioning with GitVersion - Take 2
Semantic Versioning with GitVersion - Take 2
 
Semantic Versioning with GitVersion
Semantic Versioning with GitVersionSemantic Versioning with GitVersion
Semantic Versioning with GitVersion
 
Getting started with caliburn.micro and windows phone 7
Getting started with caliburn.micro and windows phone 7Getting started with caliburn.micro and windows phone 7
Getting started with caliburn.micro and windows phone 7
 
Mmmm, chocolatey goodness!
Mmmm, chocolatey goodness!Mmmm, chocolatey goodness!
Mmmm, chocolatey goodness!
 
Continuous integration 101
Continuous integration 101Continuous integration 101
Continuous integration 101
 

Recently uploaded

UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 

Recently uploaded (20)

UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 

StyleCop breaking down the barriers to entry

  • 1. StyleCop Breaking down the barriers to entry Gary Ewan Park gep13@gep13.co.uk Twitter: @gep13 Blog: http://www.gep13.co.uk/blog
  • 2. Agenda • • • • • • • • What is StyleCop? Visual Studio Integration MSBuild Integration Using a Custom Task StyleCop Compliance Extending StyleCop Working with “Legacy” Applications Additional Tooling Support
  • 5. A Definition… “StyleCop is an open source static code analysis tool from Microsoft that checks C# code for conformance to StyleCop's recommended coding styles and a subset of Microsoft's .NET Framework Design Guidelines. StyleCop analyzes the source code, allowing it to enforce a different set of rules from FxCop.” * Reference  http://stylecop.codeplex.com/ * http://en.wikipedia.org/wiki/StyleCop
  • 6. What does that mean? • StyleCop is a “plugin” for Visual Studio 2008, 2010, and VS 11 Preview (and in a way, 2005* and Express) • It provides 162 rules over 7 categories of “style” * http://gep13.me/ie1T0V
  • 9. Demo 1 Visual Studio Integration Using StyleCop on a New Project
  • 11. This gets installed by default… During the installation you have the option to install MSBuild files. These files will be required if you want to integrate StyleCop analysis with the Visual Studio build process or a Continuous Integration Server.
  • 12. MSBuild Integration – Visual Studio To add StyleCop as part of the “Build” process in Visual Studio follow these steps: 1. Use the StyleCop.MSBuild Nuget package to install the necessary files and make file edits. 2. This edits the project file to include: 3. Add the following property in the project file to force all warnings to be treated as errors:
  • 13. Demo 2 MSBuild Integration Including StyleCop Analysis as part of the Build Process
  • 15. MSBuild Integration – Custom Task • StyleCop also includes a MSBuild task that can be used to create a custom build step • Manning Publications – Continuous Integration in .NET • http://gep13.me/MuNEL9
  • 16. Demo 3 Using a Custom Task Running StyleCop Analysis as a custom task with MSBuild and TeamCity
  • 18. Visual Studio Templates During the installation you have the option to install a new set of Visual Studio Templates, which will already by StyleCop “compliant”
  • 19. Going further with more templates… • Use StyleCop compliant code snippets • http://vssnippets.codeplex.com/ • Use StyleCop compliant project/item templates • http://vstemplates.codeplex.com/
  • 20. Talk to your Team • Get Buy-In from your Team Members • Only enable the StyleCop rules that you want to follow • Have a team meeting to decide
  • 21. Demo 4 StyleCop Compliance Using StyleCop Compliant Project/Item Templates and Code Snippets
  • 23. Add More StyleCop Rules • There are a number of projects that are extending the builtin StyleCop rules:  StyleCop+ o http://stylecopplus.codeplex.com/  JSL StyleCop o http://jslstylecop.codeplex.com/
  • 24. Create your own Custom StyleCop Rule 1. 2. 3. 4. 5. 6. Create a .Net Framework 3.5 Class Library Project in Visual Studio Add a reference to StyleCop.dll and StyleCop.Csharp.dll Create your analyzer class that inherits from SourceAnalyzer Add an XML file with the same name as the analyzer class. Set the properties of the XML file to be an Embedded Resource and not copy to the output directory Override the AnalyzeDocument method You are ready to write your own analysis code • http://gep13.me/JIn0xL
  • 25. StyleCop Contrib This CodePlex Project started out life as another Custom StyleCop Rule Library, however, now it is a Unit Testing Framework for Custom StyleCop Rules http://stylecopcontrib.codeplex.com Allows you to quickly begin testing your Rules, without the need to debug multiple instances of Visual Studio
  • 26. Demo 5 Extending StyleCop Create a Custom StyleCop Rule and then test it with Unit Tests
  • 28. Using StyleCop in an Existing Project • Turn off analysis for generated code • Surround code in a region with the text „generated code‟ within the title • Turn off StyleCop Analysis for a particular file using SourceFileList in Settings.StyleCop file • Turn off StyleCop Analysis for an entire project using Settings.StyleCop file
  • 29. Demo 6 Working with “Legacy” Applications Turning StyleCop off for an existing large project using Settings file
  • 31. Refactoring StyleCop Rules • There are plugins available for both CodeRush and ReSharper to help refactor code to be StyleCop Compliant • StyleCop For ReSharper  Now included as part of the core StyleCop installation  Automatically fixes 128 StyleCop issues during ReSharper “CleanUp Code…” • Style Ninja for CodeRush  http://code.google.com/p/dxcorecommunityplugins/wiki/ CR_StyleNinja  Fixes 23 StyleCop Issues
  • 32. ReSharper Integration During the installation you have the option to install ReSharper Integration files, these will be required if you want to be able to analyse and correct StyleCop warnings using ReSharper Refactorings.
  • 33. Demo 7 Additional Tooling Support Using ReSharper to improve StyleCop Compliance
  • 34. Questions? Feel free to email me any additional questions at gep13@gep13.co.uk

Editor's Notes

  1. Questions – feel free to ask them at any point, just throw up your hand, or if I don’t see you, feel free to shout at me.Explain what I have on my machine, i.e. all code in Local Git Repo, Git Extensions in Visual Studio, TeamCity, local Nuget Repo for a couple packagesMake sure to explain that the intention of the talk is to show how, out of the box, StyleCop can appear to be slightly “jarring”. However, there are processes and tooling that you can add/implemented that can make things easier.
  2. Ask who is currently using StyleCopAsk who is currently using FxCop – Code AnalysisCoding Standard ARE NOT the personal preference of the most senior person on the team!
  3. The rules are classified into the following categories: - Documentation - Layout - Maintainability - Naming - Ordering - Readability - SpacingStyleCop includes both GUI and command line versions of the tool. It is possible to create new rules to be used.StyleCop was re-released as an open source project in April of 2010, at http://stylecop.codeplex.com.Originally used internally within Microsoft, and later released to the public.
  4. StyleCop Analysis at: - Solution Level - Project Level - Code File LevelTurn On and Off RulesConfigure SettingsOverride Default Hungarian NotationSpecify Company Information
  5. Mention that this isn’t “required” if you use the StyleCopNuget Package
  6. The MSBuild files that are installed as part of the StyleCop installation are not actually required if you use the Nuget Package.
  7. C:\Program Files (x86)\MSBuild\Microsoft\StyleCop\v4.4
  8. StyleCop+ adds - Advanced Naming Rules - More Custom Rules - Code Line Must Not End With Whitespace - Check Allowed Indentation Characters - Check Whether Last Code Line is Empty - Code Line Must Not Be Longer Than… - Method Must Not Contain More Lines Than… - Property Must Not Contain More Lines Than…JSL StyleCop adds - More Custom Rules - Members Must be in Alphabetical Order - Don’t Compare to Boolean Constants - Local Variable Assignment Unused - Local Variables Should be Set Where They are Declared - Move Variable Declaration to Usage Level