没有 DEBUG 常量定义,#if DEBUG returns true on release build

No DEBUG constant define, #if DEBUG returns true on release build

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

我们有一个稳定的配置,配置为不定义 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 上得到 运行 时,这总是 returns 正确并阻止部署:

#if DEBUG
Console.ReadLine();
#endif

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

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

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

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

知道为什么会这样吗?

编辑 - 用于构建项目的命令(使用 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")

Build servers build. Octopus deploys.

所以我认为八达通与此问题无关。 你有像 TeamCity 这样的构建服务器吗?可能是配置有问题?

编辑:

你试试这个参数吗?

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