问题描述
Visual Studio 2013.
Visual Studio 2013.
我有一个外部 DLL,我在 csproj 文件中像这样引用它:
I have an external DLL which I am referencing like this in the csproj file:
<ItemGroup>
<Reference Include="NameOfDll">
<HintPath>PathToDllNameOfDll.dll</HintPath>
</Reference>
我希望这个引用在编译器符号存在时起作用,而在编译器符号不存在时不起作用.(为了解决第一条评论,下面,假设编译器符号称为 Fred.)
I want this reference to function when a compiler symbol exists and to not function when that compiler symbol does not exist. (To address the first comment, below, let's say the compiler symbol is called Fred.)
这个问题[ 条件参考 ]让我觉得我可以向上面显示的 Reference 元素添加一个名为 Condition 的属性,但我无法计算出赋予该属性什么值以实现我想要的效果.
This question[ Conditional Reference ]made me think I could add an attribute called Condition to the Reference element shown above but I can't work out what value to give that attribute to effect what I want.
我很乐意在 VS UI 中获得一种方法来执行此操作,但我会采用任何方法.
I'd be most happy to be given a way to do this in the VS UI but I'll take any method.
推荐答案
条件编译符号位于 DefineConstants
MSBuild 属性中.检查这是否包含您的符号:
The conditional compilation symbols are in the DefineConstants
MSBuild property. Check that this contains your symbol:
<Reference Include="NameOfDll" Condition="$(DefineConstants.Contains('Fred'))">
<HintPath>PathToDllNameOfDll.dll</HintPath>
</Reference>
为符号选择一个独特的名称.不能是另一个常量(如 Debug 或 Trace)的子字符串.
Pick a distinctive name for the symbol. Not something that could be a substring of another constant like Debug or Trace.
这篇关于如何根据编译符号有条件地引用 DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!