【问题标题】:How to force Resharper to take into account conditional compilation symbols如何强制 Resharper 考虑条件编译符号
【发布时间】:2019-02-26 21:26:49
【问题描述】:

每当我为调试配置定义条件编译符号时,当我从调试配置切换到发布配置时,编辑器视图会保留相同部分的活动代码。但是在运行时它会按预期运行。

我的 csproj 文件:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DefineConstants>STACKOVERFLOW</DefineConstants>
  </PropertyGroup>
</Project>

还有我的代码:

public static void Main()
{
    #if STACKOVERFLOW
    Console.WriteLine("Hello World!");
    #else
    Console.WriteLine("Salve Mundi!");
    #endif
    Console.ReadKey();
}

当我切换到发布配置时,Resharper 会忽略我代码的 else 分支。

如何强制 Resharper 考虑正确的编译符号?

环境:

  • Windows 10 专业版 (1803)
  • Visual Studio 2017 (15.9.7)
  • 锐器 (2018.2.3)

【问题讨论】:

    标签: c# .net resharper conditional-compilation


    【解决方案1】:

    重新加载(在 Visual Studio 中卸载和重新加载项目)该项目使 Resharper 重新考虑视图并将激活正确的代码部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-29
      • 1970-01-01
      • 2010-10-03
      • 2019-03-24
      • 2010-12-31
      相关资源
      最近更新 更多