Exercise 1: Introduction to Code Analysis
来源:互联网 发布:服务器数据丢失 编辑:程序博客网 时间:2024/06/05 09:41
In this exercise, you will learn about new Code Analysis features in Visual Studio 2010 by configuring the rule set used, performing code analysis on a sample project, and addressing some of the warnings that are raised.
- Log in as Abu Obeida Bakhach (Dev) if you have not already done so. The password is P2ssw0rd (capital letter P, the number two, the letter s, the letter s, the letter w, the number zero, the letter r, and the letter d). Please see “Working with the Visual Studio 2010 RTM Virtual Machine” for instructions on how to log into the VM.
- Open Microsoft Visual Studio from Start | All Programs |Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
- In Source Control Explorer (View | Other Windows | Source Control Explorer), navigate toTailspin Toys | Development | Iteration 2 and double-click on theTailspinToys.sln file to open the Tailspin Toys solution.
- Rebuild the solution (Build | Rebuild Solution from the main menu). This step may take a few minutes to complete.
- In Solution Explorer, left-click on the Tailspin.Model project node and selectAnalyze | Configure Code Analysis for Tailspin.Model from the main menu, which will load the project properties and go to theCode Analysis tab.Figure 1
Configuring Code Analysis for a project
Note:The Code Analysis tab is new to Visual Studio 2010, and it allows you to choose from sets of rules rather than picking and choosing from one flat list of rules, as was the case in previous versions. - Select the “Microsoft All Rules” option for the Rule Set to select the comprehensive set of rules.Figure 2
Configuring Code Analysis rule set to use
- In Solution Explorer, right-click on the Tailspin.Model project node and selectRun Code Analysis from the context menu that appears.Figure 3
Location of contextual Run Code Analysis command
- The Code Analysis feature runs through static code analysis rules as defined by Microsoft and displays the results as warnings. Scroll through the list of warnings and read a few of them.Figure 4
Code Analysis warnings
Note:Depending on the version of Tailspin Toys that you are running, you may see more or less warnings than depicted in screenshots.Code Analysis rules can also be configured to show up as errors if desired. - The warnings produced by Code Analysis provide a wealth of information including a unique category ID (such as CA1062 in screenshot above), a group name (Microsoft.Design in screenshot above), and a brief description of the problem or suggested fix, and the file location of the offending code.Note:Pressing F1 while selecting one of the warnings will take you more descriptive help online. This may not be available to you within the virtual environment.
- Find a warning that looks like it will be easy to fix quickly, such as the warning forCA1062 in the screenshot above, and double-click on it to load the location in code.Figure 5
Code Analysis errors are linked to source code
- Perform the code fix necessary to resolve the warning. For CA1062, we are told that we should validate parameter ‘item’ before using it. One potential fix can be seen in the following screenshot.Figure 6
Validating input parameter before use resolves CA1062
- Select Analyze | Run Code Analysis on Tailspin.Model from the main menu and verify that the warning disappears. There should be one less warning than before.
- Exercise 1: Introduction to Code Analysis
- Larbin Source Code Analysis 1——Introduction
- Solution for exercise 1.2-1 in Introduction to Algorithms
- Exercise 2: Suppressing Code Analysis Warnings
- Introduction to The Design and Analysis of Algorithms (1)
- 第一章 Introduction exercise 1-12
- An Introduction to Function Point Analysis
- Introduction to Lucene's analysis API
- A Gentle Introduction to Algorithm Complexity Analysis
- Introduction to LDA (Linear Discrimination Analysis)
- Introduction to Multi-threaded Code
- Introduction to Darwin Streaming Server (1) - source code organization
- Solution for exercise 1.1-4 in Introduction to Algorithms
- Solution for exercise 1.2-3 in Introduction to Algorithms
- Solution for exercise 1.3-5 in Introduction to Algorithms
- Solution for exercise 1.3-7 in Introduction to Algorithms
- Video Introduction to Bayesian Data Analysis, Part 1: What is Bayes?
- Code Exercise
- Linux下patch打补丁命令实例详解
- TC Disrupt:创新者的天堂 Copycat的盛宴
- 安装oracle时中文字符集选择
- 假如你是QQ的产品经理
- hadoop作业执行流程及代码简略解读之一整体简介
- Exercise 1: Introduction to Code Analysis
- Android动态获取资源ID并使用javabean进行赋值
- Negative margin参考网站
- 基于jquery的html 选中一行
- window 下配置Apache FTPServer
- hadoop作业执行流程及代码简略解读之二JobClient
- spring学习笔记一
- Exercise 2: Suppressing Code Analysis Warnings
- oracle安装完成后WEB配置页面