Fxcop uses dataflowrules rule set fxcop uses data flow rules

Source: Internet
Author: User
Tags xsl file xslt

After a company recently deployed a project to the production environment, it found that its memory usage only rose and fell, and it was suspected that the memory was leaked.ProgramStable Operation brings great risks.

There are two methods to solve Memory leakage: static check and dynamic monitoring. In terms of difficulty in use, dynamic monitoring is far greater than static checks. In order of use, dynamic monitoring is usually conducted first and then. A better tool for static checks is fxcop.

Fxcop is a static tool developed by Microsoft.CodeCheck tool, which has been integrated by vs since 1.36. The relationship between its independent version and vs version is: 1.35 corresponds to vs2005, 1.36 corresponds to vs2008, 10 corresponds to vs2010. The independent version can be used in two ways: UI and command line. The integrated version UI is integrated with vs, and can only be used independently by the command line.

In essence, the static code check tool uses code check rules to check the code, as does fxcop. Rules of each fxcop version are slightly different. In vs10 integrated version, a dataflowrules rule set is added, which includes a ca2000 and dispose objects before losing scope rule, release releasable objects before exiting the scope, which is the main character of today.

The software and rule set are not randomly combined. By default, fxcop of a certain version uses its own rules. However, today's situation is different. The project is 08, so it is not convenient to convert to version 10, but you want to use version 10 rules, and this rule set cannot be identified by any independent version of fxcop UI. I checked it on the Internet and said that it could be identified by the current line. I tried it for a long time and finally succeeded. Now the steps are recorded as follows. The integrated version of vs10 is used.

1. Download fxcop 10. There is no independent installation package on the official website. It is integrated into the windows SDK. You can find a separate installation package uploaded by netizens on csdn to download it.

2. Install fxcop 10, run, add the DLL to be verified, and temporarily select any one rule for analysis. The purpose is to follow the prompts to check the required DLL files, and the path will be recorded in the fxcop project file. If you use the command line directly, if the DLL is missing, there is no prompt, and an error may be reported to terminate the analysis, or the analysis may run normally but the desired results cannot be checked. When adding a DLL, pay attention to the dll version number. The new and old dll may not be replaced by each other.

3. After completing all the DLL files, cancel all default rules and save the fxcop project file. Generally, it can only be saved to the same directory of the DLL to be checked.

4. Open the fxcop project file with the suffix fxcop saved in the previous step in notepad. This is an XML file. Add the rules mentioned above in the rulefiles section:

    rulefile   name   =" $ (fxcopdir) \ rules \ dataflowrules. DLL "  enabled  =" false "  allrulesenabled  =" false"  >    rule   name   =" dispose objects before losing scope "  enabled   =" true " />     rulefile  > 

If you are familiar with this file, you will find that its name is a bit strange. The names of rules in other rule sets start with an uppercase word with no spaces in the middle, in this special rule set, the first letter of the first word is capitalized with spaces in the middle. I only need this rule. If the rule name is not specified, all rules in the rule set will be used. Because it is different from other conventional name styles, I searched for this name for a long time and finally found it through. Open any project, select this rule in code analysis, and save the project file. A "DLL name" is generated in the same directory of the Project DLL. codeanalysislog. in the XML file, the Rules/Rule/NAME records the actual name of the selected rule.

5. Use win + R to bring up the command window, Enter cmd to go to the command line, locate "Microsoft Visual Studio 10.0 \ team tools \ static analysis tools \ fxcop", and enter the command:

 
Fxcopcmd/P: ZC. fxcop/O: W: \ ZC. xml

Here, fxcopcmd is the command name,/P specifies the path of the fxcop project file, And/o specifies the output path. Wait for a minute or two and run the command line again. Then, you can view the result in the specified output path.

6. The result file is a pure XML file and specifies the XSLT file required for rendering. There is a fxcopreport in the c: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ team tools \ static analysis tools \ fxcop \ XML directory. the XSL file is obtained to the same-level directory of the result file, and then the result file is opened in Notepad. In the second row, the specified XSLT path is changed to the same-level directory. In this way, you can copy these two files at the same time and view them anytime and anywhere.

The above is the entire operation process. In one sentence, you can use the fxcop UI to generate a project file, solve DLL dependencies, manually add the required rules, and run the command line to get the result, copy the XSLT file to the same directory of the result file and change the direction of the result file's XSLT file, you can view it anywhere. Note the following.

1. No matter how hard it is, the UI of the independent version cannot identify this rule set, and the UI of vs08 integration cannot be used.

2. Each rule set corresponds to a DLL, and each rule corresponds to a class. Through decompiling these DLL files, we can see that the dataflowrules rule set inherits another set of classes called Phoenix engine on the internet. To use it successfully, an additional class library is required. visual Studio. codeanalysis. dataflowmodels. DLL "," Microsoft. visual Studio. codeanalysis. phoenix. DLL "," Microsoft. visual Studio. codeanalysis. phoenix. XML "," phx. DLL, Runtime-vccrt-win-msil.dll, etc. Independent fxcop does not have these DLL by default. Theoretically, if these DLL is supplemented, the command line of the 10 independent version can use this rule set. (This is verified by myself and can be used)

3.1.35 corresponds to. NET 2.0, 1.36 corresponds to. Net 3.5, and 10 corresponds to. Net 4.0. This rule set is included in vs10 integration. Because the platform versions are inconsistent, even if these DLL versions are added, other versions of the command line may not be able to use this rule set, including 1.35 independent, 1.36 independent, and vs08 integration.

4. A table is summarized as follows:

  1.35 independent 1.36 independent Vs08 Integration 10 independent Vs10 Integration
UI × × × ×
Command Line × × ×

ReferenceArticle:

Fxcop uses data flow rules

Is there a fxcop rule for local used idisposable's?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.