14

视觉工作室 2013。

我有一个外部 DLL,我在 csproj 文件中像这样引用它:

  <ItemGroup>
    <Reference Include="NameOfDll">
      <HintPath>Path\To\Dll\NameOfDll.dll</HintPath>
    </Reference>

我希望此引用在编译器符号存在时起作用,而在该编译器符号不存在时不起作用。(为了解决下面的第一条评论,假设编译器符号称为 Fred。)

这个问题 [ Conditional Reference ] 让我觉得我可以在上面显示的 Reference 元素中添加一个名为 Condition 的属性,但我无法确定赋予该属性什么值来实现我想要的效果。

我很高兴能在 VS UI 中获得这样做的方法,但我会采取任何方法。

4

1 回答 1

26

条件编译符号位于DefineConstantsMSBuild 属性中。检查这是否包含您的符号:

<Reference Include="NameOfDll" Condition="$(DefineConstants.Contains('Fred'))">
  <HintPath>Path\To\Dll\NameOfDll.dll</HintPath>
</Reference>

为符号选择一个独特的名称。不能是另一个常量(如 Debug 或 Trace)的子字符串。

于 2015-02-07T21:44:09.230 回答