Analyzing VC++ projects

Purpose

The Visual studio analyzer is intended to determine dependencies between C/C++ source files based on header file includes. Also IDL files and their generated files are taken into account.

This analyzer used the Microsoft.Build.Evaluation API. For proper analysis it is required that solutions compile successfully.

Selectable model view

The element hierarchy used to visualize the DSM can be based on:

Merging source and header files

A C++ module consists in most cases of a header and a source file. In many cases externally visible header files are located in a different directory the private header files or source files. For proper analysis it is better to merge them to a single location in the DSM. Three strategies are possible:

This analyzer provides more accurate results than the C++ analyzer, because include path per visual studio project are taken into account. Therefor if you analyzer VC++ chose this analyzer and not the C++ analyzer.

Pre requisites

Performing an analysis

Command line usage

Use the following command to run a analysis:

"C:\Program Files\DsmSuite\Analyzers\VisualStudio\DsmSuite.Analyzer.VisualStudio.exe" AnalyzerSettings.xml

Settings

The following settings are defined:

Setting Description
LogLevel Log level as described above
Input.Filename Full path to visual studio solution files organized in named or unnamed groups
Input.RootDirectory  
Input.SystemIncludeDirectories List of directories where system include files can be found.
Input.ExternalIncludeDirectories List of directories where third party include files can be found.
Input.InterfaceIncludeDirectories List of directories where interface include files can be found. These can be clones.
Analysis.ViewMode Base the element hierarchy on directories or solution folders and project filters
Analysis.ToolsVersion Should match installed version (14.0=VS2015 15.0=VS2017)
Transformation.IgnoredNames Names in input data which will be ignore. Defines as regular expression.
Transformation.AddTransitiveIncludes Add transitive includes.
Transformation.ModuleMergeStrategy Strategy to merge source and related header file into a single module.
Transformation.ModuleMergeRules Rules to merge header and source file directories.
Output.Filename Filename with dsi extension to which results will be written
Output.Compress Compress output file

AnalyzerSettings.xml example

Example for analyzing C++ in a D:\MyProject\MyProject.sln directory.

<?xml version="1.0" encoding="utf-8"?>
<AnalyzerSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <LogLevel>Error</LogLevel>
  <Input>
    <Filename>C:\Example.sln</Filename>
    <RootDirectory>C:\</RootDirectory>
    <SystemIncludeDirectories>
      <string>C:\Program Files (x86)\Windows Kits\8.1\Include\um</string>
      <string>C:\Program Files (x86)\Windows Kits\8.1\Include\shared</string>
      <string>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt</string>
      <string>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include</string>
      <string>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include</string>
    </SystemIncludeDirectories>
    <ExternalIncludeDirectories>
      <ExternalIncludeDirectory>
        <Path>C\:External</Path>
        <ResolveAs>External</ResolveAs>
      </ExternalIncludeDirectory>
    </ExternalIncludeDirectories>
    <InterfaceIncludeDirectories />
  </Input>
  <Analysis>
    <ToolsVersion>14.0</ToolsVersion>
    <ViewMode>SolutionView</ViewMode>
  </Analysis>
  <Transformation>
    <IgnoredNames />
    <AddTransitiveIncludes>false</AddTransitiveIncludes>
    <HeaderSourceFileMergeStrategy>None</HeaderSourceFileMergeStrategy>
    <MergeHeaderAndSourceFileDirectoryRules>
      <TransformationMergeRule>
        <From>Header Files.</From>
        <To>Source Files.</To>
      </TransformationMergeRule>
    </MergeHeaderAndSourceFileDirectoryRules>
  </Transformation>
  <Output>
    <Filename>Output.dsi</Filename>
    <Compress>true</Compress>
  </Output>
</AnalyzerSettings>

Additional Logging

The following additional logging files defined.

Log file Description
filesNotFound Source files not found in the file system
includePathsNotFound Include paths not found in the file system
pathsNotResolved Relative include files which could not be resolved to an absolute path
includeFilesNotFound Absolute include files which could not be found in the file system

The user messages log shows what percentage of the relations could be resolved. This is an indication of the reliability of the dependency model.

back