Creating a C-sharp build specification

Klocwork integrates with your build, capturing all of the information it needs to provide a centralized view of the entire code stream.

Klocwork stores this information in a structured build log -- a text file we call a build specification. The build specification is the basis of the Klocwork analysis.

It's important that the build specification is an accurate and up-to-date representation of your build. If the build specification is inaccurate, the Klocwork analysis will be inaccurate too.

A build specification is required at both the integration and local build levels.

  • For the integration build, creating a build specification is the first essential task following installation.
  • For some desktop environments, build integration happens automatically; for others, you need to create a build specification manually. If you're not sure whether you need to create a build specification manually, go to Fixing issues before check-in with Klocwork Desktop Analysis and choose your coding environment.


Before you can create a build specification, you need to install the Server or User package. See Installing Klocwork.

Capture your build settings

You can also check out our cheat sheet as a quick reference C-sharp integration build analysis - Cheat sheet.

The example uses the open-source project NAnt, version 0.85. If you're using your own source code, substitute your information for the NAnt-specific information:

The preferred method to generate build specifications for C# projects is to use kwinject in non-incremental mode. As of Klocwork 2021.1, incremental analysis is also supported.

Important: Make sure your project is clean before building it, otherwise kwinject won't capture all the build commands.

Alternatively, you can call msbuild with the /t:Rebuild option, if you also include the --overwrite option, for example:

kwinject --overwrite msbuild Project.sln /t:Rebuild /p:UseSharedCompilation=false /p:ProduceReferenceAssembly=false

Note that the msbuild options /p:UseSharedCompilation=false and /p:ProduceReferenceAssembly=false are both required, otherwise the analysis would not be as accurate.

Similarly, to generate the build specification of a .NET Core project:

kwinject dotnet msbuild Project.sln /p:UseSharedCompilation=false /p:ProduceReferenceAssembly=false

If you are using devenv instead of msbuild, the UseSharedCompilation and ProduceReferenceAssembly options can be passed through environment variables, for example:

set UseSharedCompilation=false
set ProduceReferenceAssembly=false
kwinject -w devenv Project.sln /Rebuild
For Cake projects (C# Make), there is no specific setting for the UseSharedCompilation parameter (or ProduceReferenceAssembly) in the Cake API, however it can be specified with:
.WithProperty("UseSharedCompilation", "false")

Review your build specification for accuracy

Once you've got a build specification:

  • Confirm the existence of cscompile, cslink and csconfig lines.
  • Carefully review the build specification to ensure that your compiler options have been processed properly. For more information on making sure kwinject has accurately captured your build settings, see Format of the build specification file for C# projects.

If your build specification is valid, you're ready to move to the next step: Running the C# integration build analysis.

What's next?