Thursday, October 16, 2014

Working with Code Analysis Tools in Sharepoint Using SPCorp CE and DisposeChecker

A) SPCop CE (Community Edition):
1. Download
We can down load SPCop.Setup.msi file version 5.1.4.9436 in the following location
Supports: It supports Visual Studio 2013, 2012, 2010
2. Installation: After downloading SPCop.Setup.msi install this SPCop EC.
3. After Installing it is directly Attach to Visual Studio 2013 As follows

 

Righty click on Solution
Select SPCop Community Edition
Next click on Run SharePoint Code Check
SPCop CE Analysis the Code it displays error messages and warning messages as follows




In above Screen we can find out non disposed objects and others details.

B) SPDispose Check Static Analysis:
1. Download
We can down load SPDisposeCheckRules-VS2012.rar file in the following location
Supports: It supports Visual Studio 2013
2. Installation: After downloading extract zip file it contains dll and exe files
 Now right click on SPDisposeCheck.exe install.
We can analysis code in two ways

i.                    With visual studio 2013
Attach SPDisposeCheck to visual studio 2013  
Open solution file click on project and select properties next click on code analysis
Check Enable code Analysis on the build
Click on open button  check SPDisposeCheck and change it action to Error As follows

Click save then it ask rule name gave rule name give rule name (ex: rule1) and click on save


Select Rule Set and browse Rule1 file and save
Now build the project it shows the following warnings 


Note: this tool is analysis only try catch blocks.



ii.                  With Command prompt
Open the command prompt
Change the directory to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\FxCop\Rules.
Using bellow command
Cd C:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\FxCop\Rules
SPDisposeCheck.exe D:\Dlls Axalta.Global.DcpIformsTemplate.dll

 


Note:
If we have used SPContext.Site, SPContext.Current.Site, SPContext.Web, and SPContext.Current.Web to get the web or site objects then no need to dispose these Objects explicitly as it will be handled by SharePoint .

If we have used like  SPSite oSPsite = new SPSite("http://server") , SPWeb oSPWeb = oSPSite.OpenWeb() 
then we need to dispose the Objects by use of using statements or calling object.Dispose() in Finally Block.
 
 For more information Please go through the below url for your reference 
 


No comments:

Post a Comment