|
| 1 | +--- |
| 2 | +title: "Analyze Visual Basic and C# code quality in Store apps using Visual Studio static code analysis" |
| 3 | +ms.custom: na |
| 4 | +ms.date: "10/14/2016" |
| 5 | +ms.prod: "visual-studio-dev14" |
| 6 | +ms.reviewer: na |
| 7 | +ms.suite: na |
| 8 | +ms.technology: |
| 9 | + - "vs-ide-general" |
| 10 | +ms.tgt_pltfrm: na |
| 11 | +ms.topic: "article" |
| 12 | +f1_keywords: |
| 13 | + - "vs.codeanalysis.propertypages.csvb.express" |
| 14 | +ms.assetid: cab553fc-19a9-4cbf-858e-8200258ffe50 |
| 15 | +caps.latest.revision: 14 |
| 16 | +ms.author: "douge" |
| 17 | +manager: "douge" |
| 18 | +translation.priority.ht: |
| 19 | + - "cs-cz" |
| 20 | + - "de-de" |
| 21 | + - "es-es" |
| 22 | + - "fr-fr" |
| 23 | + - "it-it" |
| 24 | + - "ja-jp" |
| 25 | + - "ko-kr" |
| 26 | + - "pl-pl" |
| 27 | + - "pt-br" |
| 28 | + - "ru-ru" |
| 29 | + - "tr-tr" |
| 30 | + - "zh-cn" |
| 31 | + - "zh-tw" |
| 32 | +--- |
| 33 | +# Analyze Visual Basic and C# code quality in Store apps using Visual Studio static code analysis |
| 34 | + |
| 35 | + |
| 36 | + The code analysis tool in Visual Studio Express examines your code for a set of common defects and violations of good programming practice. Code analysis warnings differ from compiler errors and warnings because the code analysis tool searches for specific code patterns that are valid but could still create issues for you or other people who use your code. Code analysis can also find defects in your code that are difficult to discover through testing. Running the code analysis tool at regular intervals during your development process can enhance the quality of your completed app. |
| 37 | + |
| 38 | +> [!NOTE] |
| 39 | +> In Visual Studio Ultimate, Visual Studio Premium, and Visual Studio Professional, you can use the full functionality of code analysis. See [Analyzing Application Quality by Using Code Analysis Tools](http://msdn.microsoft.com/library/dd264897.aspx) in the MSDN Library. |
| 40 | + |
| 41 | +## In this topic |
| 42 | + You can learn about: |
| 43 | + |
| 44 | + [Running code analysis](../codequality/analyze-visual-basic-and-csharp-code-quality-in-store-apps-using-visual-studio-static-code-analysis.md#BKMK_Run) |
| 45 | + |
| 46 | + [Analyzing and resolving code analysis warnings](../codequality/analyze-visual-basic-and-csharp-code-quality-in-store-apps-using-visual-studio-static-code-analysis.md#BKMK_Analyze) |
| 47 | + |
| 48 | + [Suppressing code analysis warnings](../codequality/analyze-visual-basic-and-csharp-code-quality-in-store-apps-using-visual-studio-static-code-analysis.md#BKMK_Suppress) |
| 49 | + |
| 50 | + [Searching and filtering code analysis results](../codequality/analyze-visual-basic-and-csharp-code-quality-in-store-apps-using-visual-studio-static-code-analysis.md#BKMK_Search) |
| 51 | + |
| 52 | + [Visual Basic and C# code analysis warnings](../codequality/analyze-visual-basic-and-csharp-code-quality-in-store-apps-using-visual-studio-static-code-analysis.md#BKMK_Warnings) |
| 53 | + |
| 54 | +## <a name="BKMK_Run"></a> Running code analysis |
| 55 | + To run code analysis on your Visual Studio solution: |
| 56 | + |
| 57 | +- On the **Build** menu, choose **Run Code Analysis on Solution**. |
| 58 | + |
| 59 | + To automatically run code analysis each time you build a project: |
| 60 | + |
| 61 | +1. Right-click the project name in Solution Explorer and then choose **Properties**. |
| 62 | + |
| 63 | +2. In the project property page, choose **Code Analysis** and then choose **Enable Code Analysis on Build (defines CODEANALYSIS constant)**. |
| 64 | + |
| 65 | + The solution is compiled and code analysis runs. Results appear in the Code Analysis window. |
| 66 | + |
| 67 | +  |
| 68 | + |
| 69 | +## <a name="BKMK_Analyze"></a> Analyzing and resolving code analysis warnings |
| 70 | + To analyze a specific warning, click the title of the warning in the Code Analysis window. The warning expands to display detailed information about the issue. |
| 71 | + |
| 72 | +  |
| 73 | + |
| 74 | + When you expand a warning, the line of code that caused the warning is highlighted in the Visual Studio code editor. |
| 75 | + |
| 76 | +  |
| 77 | + |
| 78 | + After you understand the issue, you can resolve it in your code. Then rerun code analysis to make sure that the warning no longer appears in the Code Analysis window, and that your fix has not raised new warnings. |
| 79 | + |
| 80 | +> [!TIP] |
| 81 | +> You can rerun code analysis from the Code Analysis window. Click the **Analyze** button and choose the scope of the analysis. You can rerun analysis on the entire solution or on a selected project. |
| 82 | + |
| 83 | +## <a name="BKMK_Suppress"></a> Suppressing code analysis warnings |
| 84 | + There are times when you might decide not to fix a code analysis warning. You might decide that resolving the warning requires too much recoding in relation to the probability that the issue will arise in any real-world implementation of your code. Or you might believe that the analysis that is used in the warning is inappropriate for the particular context. You can suppress individual warnings so that they no longer appear in the Code Analysis window. |
| 85 | + |
| 86 | + To suppress a warning: |
| 87 | + |
| 88 | +1. If the detailed information is not displayed, click the title of the warning to expand it. |
| 89 | + |
| 90 | +2. Choose the **Actions** link at the bottom of the warning. |
| 91 | + |
| 92 | +3. Point to **Suppress Message** and then choose either **In Source** or **In Suppression File**. |
| 93 | + |
| 94 | + - **In Source** inserts a `SuppressMessage` attribute in the source file above the method that generated the warning. This makes the suppression more discoverable. |
| 95 | + |
| 96 | + - **In Suppression File** adds a `SuppressMessage` attribute to the **GlobalSuppressions.cs** file of the project. This can make the management of suppressions easier. Note that the `SuppressMessage` attribute added to **GlobalSuppression.cs** also targets the method that generated the warning. It does not suppress the warning globally. |
| 97 | + |
| 98 | + Your decision whether to suppress the warning in the source file or in the suppression file depends on your coding style and needs. |
| 99 | + |
| 100 | +## <a name="BKMK_Search"></a> Searching and filtering code analysis results |
| 101 | + You can search long lists of warning messages and you can filter warnings in multi-project solutions. |
| 102 | + |
| 103 | +  |
| 104 | + |
| 105 | + In [!INCLUDE[vs_dev11_expwin_long](../codequality/includes/vs_dev11_expwin_long_md.md)], all code analysis warnings have the severity level of Warning. |
| 106 | + |
| 107 | +## <a name="BKMK_Warnings"></a> Visual Basic and C# code analysis warnings |
| 108 | + Code analysis raises the following warnings: |
| 109 | + |
| 110 | + [CA1001: Types that own disposable fields should be disposable](http://msdn.microsoft.com/library/ms182172.aspx) |
| 111 | + |
| 112 | + [CA1821: Remove empty finalizers](http://msdn.microsoft.com/library/bb264476.aspx) |
| 113 | + |
| 114 | + [CA2213: Disposable fields should be disposed](http://msdn.microsoft.com/library/ms182328.aspx) |
| 115 | + |
| 116 | + [CA2229: Implement serialization constructors](http://msdn.microsoft.com/library/ms182343.aspx) |
| 117 | + |
| 118 | + [CA2231: Overload operator equals on overriding ValueType.Equals](http://msdn.microsoft.com/library/ms182359.aspx) |
0 commit comments