没有DEBUG常量定义,#if DEBUG在发布版本时返回true

本文关键字:DEBUG 版本 返回 true 定义 常量 #if 没有 布版本 | 更新日期: 2023-09-27 18:09:41

我们有一个控制台应用程序,我们使用它来调用DbUp(创建db,更新,测试数据等)。

我们有一个配置,Stable,它被配置为不定义DEBUG常量:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Stable|AnyCPU'">
    <OutputPath>bin'Stable'</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <Prefer32Bit>true</Prefer32Bit>
  </PropertyGroup>

然而,当它在Octopus上运行时,它总是返回true并阻止部署:

#if DEBUG
Console.ReadLine();
#endif

当我切换到稳定配置本地(VS),它运行和退出预期。

当我切换到本地调试配置(VS)时,它运行并等待输入,如预期的。

如果我完全注释掉这些行,它在Octopus上运行良好(退出,部署在Octopus上完成)。

这让我质疑我在生活中的所有选择。

知道为什么会这样吗?

EDIT -用于构建项目的命令(使用TeamCity)

# Database
Invoke-Msbuild "$rootDir'artifacts'output'Database" `
             "$rootDir'MyClient.Database'MyClient.Database.csproj" `
             -target 'build' `
             -toolsVersion 4.0 `
             -maxCpuCount 8 `
             -VisualStudioVersion 14.0 `
             -logPath "$rootDir'artifacts'logs'Database" `
             -namespace 'MyClient' `
             -customParameters @('/property:RunOctoPack=true', "/property:OctoPackPackageVersion=$version", "/property:OctoPackNuGetProperties=env=$environment")

没有DEBUG常量定义,#if DEBUG在发布版本时返回true

构建服务器构建。章鱼部署。

所以我不认为八达通与这个问题有关。你们有像TeamCity这样的构建服务器吗?也许配置有什么问题?

编辑:

是否尝试此参数?

-MsBuildParameters "/target:Clean;Build/property:Configuration=Stable;Platform="Mixed Platforms"