Main Content

Configure Polyspace as You Code Extension in Visual Studio

Polyspace® as You Code allows you to find bugs and coding rule violations while you work in Visual Studio® IDE.

After you install the Polyspace as You Code analysis engine and Visual Studio extension, configure the extension so that a Polyspace analysis runs smoothly when you save your code or explicitly start an analysis. An analysis has run smoothly if results appear as you expect, either as source code markers with tooltips or in a list on the Results List pane.

To configure the extension, in Visual Studio, select Tools > Options and select the Polyspace as You Code node in the Options window. Under the Polyspace as You Code node, select:

  • General to configure the installation folder and working directory

  • Analysis Options to configure the analysis options for the projects

  • Baseline to configure the use of analysis results you download from Polyspace Access™ as a baseline

To save your configuration, click OK. All settings retain their current values when you reopen the extension.

Import and Export Polyspace as You Code Settings in Visual Studio

In situations where several developers all require the same project configuration, it can be easier to set up one instance of Polyspace as You Code and export the extension settings as a vssettings file. You can then share the settings file with the developers who require it and import the settings into Visual Studio.

Visual Studio contains an Import and Export Settings option that allows you to export your selected environment settings including your Polyspace as You Code configuration settings.

To export your Polyspace as You Code settings:

  1. Open the Import and Export Settings Wizard by going to Tools > Import and Export Settings....

  2. Select Export selected environment settings then select Next.

  3. Uncheck anything you do not want to export in addition to the Polyspace as You Code settings. Expand the Options node and select Polyspace as You Code to export all Polyspace as You Code settings. Alternatively, expand the Polyspace as You Code node to customize which Polyspace as You Code settings to export. Then click Next.

  4. Enter a name for your settings file and select a directory to save your settings file. Then click Finish.

You can import Polyspace as You Code settings in three ways.

  1. Use the Import and Export Settings Wizard in Visual Studio.

    1. Open the Import and Export Settings Wizard by going to Tools > Import and Export Settings....

    2. Select Import selected environment settings and then Next.

    3. Choose if you want to save your current settings or select not to and click Next.

    4. Click the Browse button to navigate to your settings file and open it. Expand the All Settings and Options nodes to confirm all your Polyspace as You Code settings are selected, then click Finish.

  2. Import settings from the Visual Studio Command Window.

    Click on View > Other Windows > Command Window. In the command window, enter the command replacing PathToSettingsFile.vssettings with your own settings full file path.

    Tools.ImportandExportSettings/import:PathToSettingsFile.vssettings 

  3. Create a shortcut to the Visual Studio program and append the settings file to the Target value. For example:

    "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\devenv.exe" /ResetSettings <PathToSettingsFile.vssettings>

Specify Polyspace as You Code Preferences

Specify general configuration settings such as the root folder of your Polyspace as You Code installation, the port the extension uses, and your working directory.

SettingDescription
Polyspace installation folder

Root folder of the Polyspace as You Code installation, for example, C:\Program Files\Polyspace as You Code\R2024b.

Working directory

Folder where Polyspace stores analysis results. Each new run overwrites results of the previous run.

The default working directory is stored under your system temporary folder:

  • Windows®%temp%, for example C:\Users\jsmith\AppData\Local\Temp

  • Linux®/tmp

Justification catalog

Specify the full file path of the justification catalog JSON file.

Use this setting if your team or organization has a predefined set of comments that they use to justify results. You can store these justifications in a catalog file and associate one or more justifications with a specific result or result family.

If you use the Polyspace syntax to annotate a result, the annotation comment is autofilled with the justifications that you store in the catalog for that result. For details of the Polyspace syntax, see Annotation Syntax Details (Polyspace Bug Finder).

To create a justification catalog, see Use a Justification Catalog to Autocomplete Annotations in Polyspace as You Code plugins.

Debug Mode

Option to enable or disable debugging.

  • off (default) — The Console view shows only errors, warnings, and status messages such as messages about the start and end of analysis.

  • on — The Console view shows all debugging information. Enable this setting to troubleshoot issues with the Visual Studio extension.

Help Improve Polyspace as You Code

Option to enable or disable the sharing of user experience information with MathWorks®.

  • on (default) — Polyspace shares user experience information with MathWorks and uses this information to improve the Visual Studio extension.

  • off — Polyspace does not share user experience information.

Port

Port number that the Polyspace as You Code extension uses on startup to establish an internal connection with the analysis engine. Use this setting if your machine is configured with a firewall and you want to specify an open port in the firewall.

By default, the extension specifies port 0 and Visual Studio queries your system for an available port and uses whichever port your system returns.

If you run multiple instances of Visual Studio that access different workspaces, specify a different port for each instance.

If you change this setting, you might need to restart Visual Studio. If you let Polyspace obtain a port number automatically (port 0), the extension could connect to a different port once Visual Studio restarts. For certain configurations, this requires you to regenerate your build options. See Generate Build Options for Polyspace as You Code Analysis in Visual Studio.

Configure Analysis Settings

Specify which actions the extension performs when you save your code and how the extension obtains information about your build system.

SettingDescription
Add to Quality Monitoring list on save

Option to add files to the Quality Monitoring list when you save the file. Polyspace as You Code analyzes only files in this list.

  • on (default) — Polyspace adds the current file to the Quality Monitoring list when you save the file.

  • off — Add files to the Quality Monitoring list manually. To add a file manually, right-click the file in the editor or the Solution Explorer view.

Start analysis on save

Option to select when Polyspace as You Code runs on files that are in the Quality Monitoring list.

  • on — Polyspace as You Code runs each time you save your code.

  • off (default) — Run the analysis manually. Right-click the source code or a file in the Project Explorer and select Run Polyspace Analysis.

Perform analysis in fast-mode

Toggle on or off fast analysis mode. This option is disabled by default.

Fast analysis decreases the duration of your Polyspace as You Code analysis by checking only for specific types of issues. This option enables only checkers for issues that are syntactic and do not require abstraction or data flow calculations. Polyspace excludes checkers that are not syntactic or require abstraction of the code from a fast analysis. These exclusions are in addition to the Checkers Deactivated in Polyspace as You Code Analysis.

Use fast analysis to iteratively identify and address bugs that are smaller in scope and addressable earlier in the development process. To take full advantage of the defects that Polyspace as You Code can find, use fast analysis as a precursor to a full Polyspace as You Code analysis of your code.

The fast-mode analyzed icon icon shows next to files you analyze in fast-mode. Enabling fast-mode affects all files in the Quality Monitoring list.

The Configuration view shows Fast analysis mode: On when the option is enabled. You can toggle the option on or off from this pane by clicking the option.

Analysis Setup

Option to select between manual setup and a script.

  • Manual setup (default) — Set up Polyspace as You Code through extension settings. Specify build-related options and other options in the Manual setup group of settings.

  • Script — Run a script each time you save your code (or right-click a source file and select Run Polyspace Analysis). Specify the path of the script file in Script File.

Set Up Analysis by Using Script

Use these settings to run a script each time you save your code or explicitly run an analysis.

SettingDescription
Script File

Use a script if you switch between files from components that have different build configurations or you use a custom tool to set up your build environment.

Full path to a script that runs each time you start a Polyspace as You Code analysis. You can write the script in any language. On Windows, the extension supports scripting languages only for scripts that are executable from the Command Prompt window.

Use this setting if you choose Script for Analysis Setup.

The extension passes these setting values as parameters to the script:

  • Path of the current file as the first argument

  • Working directory as the second argument.

  • Polyspace installation folder as the third argument.

Optionally, the extension passes these additional settings to the script if you specify them:

  • The path of the options file from Other Analysis Options File, prefixed by -options-file. For example, if you specify the file C:\polyspace\myOpts.txt, the extension passes -options-file C:\polyspace\myOpts.txt as a parameter.

  • The path of the checkers activation XML file from Checkers File, prefixed by -checkers-activation-file. For example, if you specify the file C:\polyspace\myCheckers.xml, the extension passes -checkers-activation-file C:\polyspace\myCheckers.xml as a parameter.

  • Any additional parameters you specify with the setting Script File Arguments.

Script File Arguments

Additional parameters that the extension passes to the script when you run an analysis. For example, running a command on preprocessed files to work around a compilation error. See Command/script to apply to preprocessed files (-post-preprocessing-command) (Polyspace Bug Finder).

For example, this Windows batch script assigns the paths of the source file (SOURCES), the results folder (RESULTS_FOLDER), and the installation folder (INSTALL_DIR), and assigns any additional parameters to OTHER_PARAMS. The script then analyzes the current file, using any analysis options stored in OTHER_PARAMS, and imports the review information from a previously downloaded baseline:

@echo off

set SOURCES=%1
set RESULTS_FOLDER=%2
set INSTALL_DIR=%3
set ANALYZE=%INSTALL_DIR%\polyspace\bin\polyspace-bug-finder-access.exe
set BASELINE_DIR=%RESULTS_FOLDER%\..\..\..\baseline

set OTHER_PARAMS=
REM loop through additional parameters if any
:loop
    if [%4] == [] (
    goto :done)
    set OTHER_PARAMS=%OTHER_PARAMS% %4
    shift
    goto :loop
:done

"%ANALYZE%" -sources %SOURCES% -import-comments %BASELINE_DIR%^
 -results-dir %RESULTS_FOLDER% %OTHER_PARAMS% 
IF %ERRORLEVEL% NEQ 0 EXIT 1
For more on downloading a baseline and importing its review information at the command line, see Set Baseline Polyspace as You Code Results on Command Line.

If you set Analysis Setup to Script, the extension ignores the Manual setup and Baseline settings.

Note

The Polyspace as You Code extension does not check the exit status of the commands in your script. Make sure your script checks exit codes (for example, by using %ERRORLEVEL%) and returns a meaningful exit status.

Typically, the Polyspace binaries return 0 on success and a nonzero value on failure.

Set Up Analysis Manually

Use these settings to provide Polyspace as You Code with your build configuration specifics and analysis options.

SettingDescription
Build

Specifics of your build configuration. Provide Polyspace as You Code with build configuration information such as data type sizes and compiler macro definitions so that the analysis runs without errors. For more information on how to generate these options, see Generate Build Options for Polyspace as You Code Analysis in Visual Studio.

  • Build options file not required (default)

    The extension does not require Polyspace options related to your build configuration. The analysis uses the default Polyspace options related to your build configuration. This is a basic option for simple projects.

  • Get from build command

    The analysis traces the build command that you specify and generates a build options file.

    Specify the build command in Build Command. For example, make -B. Click Generate build options icon in the Configuration view of the Polyspace as You Code perspective to have the extension generate build options from your build command. See Get Build Configuration from Build Command.

  • Get from Visual Studio C/C++ project

    The analysis extracts the build configuration from the Visual Studio project and generates a build options file.

    If your workspace contains multiple projects, Polyspace extracts the build options for all the projects and then applies only the relevant options when you analyze a file in a specific project.

  • Get from JSON Compilation Database file

    The analysis extracts the build configuration from the JSON compilation database that you specify and generates a build options file. See Get Build Configuration from JSON Compilation Database.

    Specify the full path to the JSON file (typically named compile_commands.json) in JSON Compilation Database file.

    If you use a build system generator such as CMake, you can use this setting to set up Polyspace as You Code. For example, if you use CMake projects in Visual Studio, CMake also allows you to generate a JSON compilation database with the commands used for building the project. You can then provide the path to the compilation database to JSON Compilation Database file. For an example of how to generate this JSON file, see Create Polyspace Options File from JSON Compilation Database (Polyspace Bug Finder).

  • Get from Polyspace build options file

    When you select this value, you provide an options file that you generate or fill in manually with all the necessary build options. See Specify Analysis Options Manually.

    Specify the full path of the options file in Polyspace Build Options File.

Build Command

Build command name exactly as you would enter on a command-line terminal or console.

Use a build command that performs a complete build of all files in your workspace and not an incremental build.

Use this setting if you select Get from build command from the Build list. See Get Build Configuration from Build Command.

JSON Compilation Database file

Full path to a JSON compilation database file (typically named compile_commands.json).

Use a build command that performs a complete build of all files in your workspace and not an incremental build.

Use this setting if you select Get from JSON Compilation Database file from the Build list. See Create Polyspace Options File from JSON Compilation Database (Polyspace Bug Finder).

Polyspace Build Options File

Full path to a Polyspace build options file. The options file is a text file with one Polyspace analysis option per line.

Use this setting if you select Get from Polyspace build options file from the Build list. See Options Files for Polyspace Analysis (Polyspace Bug Finder).

Checkers File

Path to a checkers configuration file.

To create this file, click Configure checkers icon in the Configuration view of the Polyspace as You Code perspective. Select the checkers that you want to enable and save the file.

If you select Script from the Analysis Setup list, the extension passes the checkers configuration file path prefixed with -checkers-activation-file as a parameter to the script.

See also Configure Checkers for Polyspace as You Code in Visual Studio.

Other Analysis Option File

Path to an options file. The options file contains one Polyspace analysis option per line. For example:

-D _WIN32
-termination-functions exit_handler

You typically do not need to specify additional options in an options file. However, using an options file is helpful in some situations. For example, if you want to manually specify Polyspace options related to your build command, select Build options file not required from the Build list and enter the options in an options file.

If you select Script the Analysis Setup list, the extension passes the options file path prefixed with -options-file as a parameter to the script.

See also Options Files for Polyspace Analysis (Polyspace Bug Finder).

Configure Baseline Settings

Use these settings to select whether you import review information from a baseline run into your analysis and to configure the connection to a Polyspace Access Server from which you download the baseline.

SettingDescription
Show Baseline information

Method for using information from the baseline run:

  • Show local findings only (default)

    When you run an analysis, Polyspace does not use information from the baseline run. You see only local findings in the Error List pane.

  • Show local findings and baseline info

    When you run an analysis, Polyspace imports review information from the baseline run. Results that are already justified in the baseline run are suppressed in the Error List pane.

  • Show new findings only

    When you run an analysis, Polyspace imports review information from the baseline run. Results that are already present in the baseline run are suppressed in the Error List pane.

    Select this value to focus only on new findings.

See also Set Baseline Polyspace as You Code Results in Visual Studio.

Polyspace Access URL

URL of the Polyspace Access instance from which you get a baseline.

After you obtain a baseline from Polyspace Access, subsequent runs of Polyspace as You Code allow you to distinguish between new results and results that are present in existing code.

See also Set Baseline Polyspace as You Code Results in Visual Studio.

Polyspace Access Login

Username that you use to log in to Polyspace Access.

Later, when you click the Download baseline icon in the Baseline view of the Polyspace as You Code perspective, Polyspace prompts you for the password that corresponds to this username.

Project path

Path of the project in the Polyspace Access Project Explorer that you use as a baseline.

Related Topics