Getting started in Visual Studio for C-sharp projects

From current

Desktop analysis > Visual Studio C# > Getting started in Visual Studio for C-sharp projects

Contents

Prerequisites and setup considerations

Installation

Before you can analyze your source code, you need to install the Klocwork User package.

An integration project to connect to

Connected desktop is a key step in harnessing the power of Insight. Before you can connect, an integration project must be set up and analyzed on the Klocwork Server. For more information about integration projects, see Integration build analysis.

If you don't connect to an integration project, this is referred to as standalone desktop.

Connect to a project on the Klocwork Server

Note: If you see a login dialog, enter the credentials provided by your Klocwork administrator, or your LDAP or NIS user name and password. See Authentication dialog in Visual Studio.

You connect to a server project to share analysis results, issue-status updates, and comments with the system-build analysis and among team members.

Note: If your solution contains both C/C++ and C# projects, you'll need to connect your solution with two projects on the Klocwork Server--a C/C++ integration project and a C# integration project. For more information, see Analyzing mixed C/C++ and C-sharp projects. Connecting to both integration projects ensures that C/C++ and C# issues are synchronized between the server and the desktop.

Contact your Klocwork administrator for more information about available server projects.

  1. Right-click a solution in the Solution Explorer and select Klocwork Properties.
    Troubleshooting: Can't see Klocwork Properties in the menu? See Cannot access Klocwork Properties in Visual Studio.
    The Klocwork Properties dialog appears.
  2. In the Klocwork Project list, select the integration project you want to connect to.
    Optional: To view an updated list of integration projects on the Klocwork Server, click the Refresh button.
  3. Click OK.
    Tip: You only have to do this step once, before your first analysis for a project.

Run the analysis

  • Right-click your solution in the Solution Explorer and click Analyze Solution.
  • Right-click your project in the Solution Explorer and click Analyze Selection.
    Tip: If you need to stop the analysis, go to Build > Stop Analysis.

Default filtering is set to show issues for all source files for the project or solution.

Review and investigate

In the Klocwork Issue window, you can:

  • Group by VS group by taxonomy.png taxonomy, VS group by file.png file, VS group by severity.png severity, or VS group by code.png issue code.
Note: If you've grouped by taxonomy and the same issue was detected in each taxonomy, you'll see that issue listed twice (in each applicable taxonomy). This is the only time you'd see the same issue listed twice. Grouping by taxonomy allows you to focus only violations of a particular standard.
  • Filter issues by Severity, Owner and Taxonomy.
  • Filter to show only local issues VS show local issues.png.
  • Filter to show issues only in the active file VS show active file.png.
  • Double-click an issue in the list to see it in source code and to view traceback.
    Traceback identifies and describes statements in the source code that contribute to issues. Traceback lines link directly to the source code and follow execution order.
    Click the traceback statements to find problems that led to the issue you are viewing in the list. Key statements that contribute to issues are marked with red rectangles and include a description of the problem.
    Tip: Traceback may not be available for all issues. If you don’t see any traceback for the error selected from the list of issues, it means that the problem associated with the issue is confined to one line of code.
  • Get help on an issue by selecting it and clicking F1.

Troubleshooting

Locate and fix local issues

If you have a connected desktop project, you may want to focus on only the issues you've injected into your project, so that you can fix them before checking in your code.

By default, Klocwork Insight shows all detected issues whether their origin is Local or System. Local issues are those you've introduced since the last integration build analysis; System issues are those that exist in the integration build and the desktop analysis.

  1. Filter to show only local issues VS show local issues.png
  2. Fix the issue and re-run the analysis.
    When the issue disappears from the list, it's fixed.

For more information about filtering, see Filtering issues on the desktop.

Ignore the remaining issues

If there's any issue that you don't care about, you can change it's status to Ignore.

  1. Right-click an issue in the list or the red Red chevron.png or yellow Yellow chevron.png chevron icon in the left gutter and select Ignore defect.
  2. The issue disappears from your issue list.

The list of issues updates to reflect the changes you made.

What's next?

Now that you've run your first desktop analysis, you may want to check out additional help resources: