VSoft Technologies Blogs

rss

VSoft Technologies Blogs - posts about our products and software development.

When deploying dotnet applications to production, the difference between a development build and a properly configured production build can be significant. MSBuild provides numerous properties that allow you to optimize your builds for performance, security, and reliability. This article explores essential MSBuild properties for production builds, with particular focus on configuration for CI servers like Continua CI.

Core Production Build Properties

Release Configuration

The foundation of any production build starts with the Release configuration:


  true
  portable
  true

Optimize enables compiler optimizations that improve runtime performance by inlining methods, removing dead code, and performing other optimizations. DebugType set to "portable" creates portable PDB files that work across platforms while maintaining debugging capabilities. DebugSymbols should remain true even in production to enable proper stack traces and debugging when issues occur.

Deterministic Builds

Deterministic builds ensure that identical source code produces identical binaries, which is crucial for security auditing and reproducible deployments:


  true
  path1=sourcePath1,path2=sourcePath2

PathMap removes replaces the actual paths in your projects, so instead of having "c:\CI_AWS\WS\123\srs\myclass.cs" baked into your executable, you get something like ".\src\myclass.cs" .

The syntax is straightforward - path1 is the real path on your build machine, and sourcePath1 is what you want it to look like in the output. If you need to map multiple paths, just separate them with commas.

CI-Specific Properties

ContinuousIntegrationBuild

One of the most important properties for CI environments is ContinuousIntegrationBuild. According to the Microsoft documentation, this property enables several CI-specific optimizations:

  • Suppresses certain warnings that are only relevant during development
  • Enables deterministic builds by default
  • Optimizes source link generation for better debugging experience
  • Improves build reproducibility

For Continua CI, you can configure this property using the built-in ContinuaCI.Version environment variable:


  true

Alternatively, you can set it in your CI build configuration by adding ContinuousIntegrationBuild=true to the MSBuild Action Properties list.

Build Metadata

Including build metadata helps with traceability and debugging:


  $(ContinuaCI.Build.LatestChangeset.Revision)
  $(ContinuaCI.Build.Version)+$(SourceRevisionId)

This embeds the source control revision ID into the assembly, making it easier to identify which exact code version is running in production. Most CI servers provide information like revision, version etc using environment variables.

Security and Code Quality Properties

Treat Warnings as Errors

In production builds, warnings often indicate potential issues that should be addressed:


  true
  CS1591

TreatWarningsAsErrors ensures your production code has no compiler warnings. WarningsNotAsErrors allows you to exclude specific warnings (like CS1591 for missing XML documentation) that shouldn't break the build.

Code Analysis

Enable static code analysis for production builds:


  true
  latest
  true

Nullable Reference Types

For C# 8.0+ projects, enable nullable reference types to catch potential null reference exceptions:


  enable
  true

This option can be quite painful to enable on an existing code base - be prepared for a lot of clean up work!

Performance Optimization Properties

Ahead-of-Time Compilation

For applications where startup performance is critical, consider enabling ReadyToRun:


  true

Note that ReadyToRun is platform specific - you must specify a Runtime Identifier (e.g., win-x64, linux-arm64) when publishing with PublishReadyToRun=true.

Trimming for Self-Contained Deployments

For self-contained deployments, enable IL trimming to reduce application size:


  true
  partial

Be cautious with trimming as it can break applications that rely heavily on reflection.

Assembly and Versioning Properties

Strong Naming

For libraries that will be consumed by other applications:


  true
  key.snk

Version Information

Properly configure version information for easier identification:


  1.0.0.0
  $(BuildNumber)
  $(ProductVersion)

Output and Packaging Properties

Symbol Package Generation

For NuGet packages, include symbol packages for debugging:


  true
  snupkg

Enable Source Link for better debugging experience:


  true
  true

Platform-Specific Optimizations

Reference the Microsoft documentation on code generation options for platform-specific optimizations:


  x64
  false

Conclusion

Properly configuring MSBuild properties for production builds is essential for creating robust, performant, and maintainable applications. The ContinuousIntegrationBuild property provides an excellent foundation for CI-optimized builds. Remember to test these configurations thoroughly in your CI environment before deploying to production, as some optimizations may have unexpected effects on applications that rely heavily on reflection or dynamic code generation.

Showing 0 Comment
your Comment will be showing after administrator's approval







b i u quote



Save Comment