I\'m possibly just blind, but is there a command line to specify conditional compilation symbols in MSBUILD?
I currently have this Line in my buildscript:
What is said in the answers is valid for C# code, and also for ASP.NET "codebehind" C# code. For ASP.NET web projects, if you want to do conditional compilation in the ASPX pages as well, it works a bit differently to conditionally render HTML on the page (note I've removed MasterPageFile="..." AutoEventWireup="true" CodeBehind="..." Inherits="..." which you usually have in the <%@ ... %> declaration as well):
<%@ Page Title="MyPage" Language="C#" CompilerOptions="/d:DebugSym1;DebugSym2" %>
<% #if DebugSym1 %>
Section1
<% #else %>
(Section 1 skipped)
<% #endif %>
<% #if DebugSym2 %>
Section2
<% #else %>
(Section 2 skipped)
<% #endif %>
If you remove DebugSym1 or DebugSym2 from the CompilerOptions, then the #else part of the relevant #if statement is rendered.
I thought this was worth mentioning for completeness of this topic and can save you time. More you can find in this article, if you're interested.