msbuild, defining Conditional Compilation Symbols

前端 未结 4 2171
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 02:59

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:

         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 03:04

    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.

提交回复
热议问题