如何有条件地引用基于一个编译符号一个DLL? [英] How to conditionally reference a DLL based on a compilation symbol?

查看:297
本文介绍了如何有条件地引用基于一个编译符号一个DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的Visual Studio 2013

Visual Studio 2013.

我有我在的csproj文件中引用这样的外部DLL:

I have an external DLL which I am referencing like this in the csproj file:

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



我想这个引用时,编译器符号存在,并且当编译器符号还不到无法正常运作存在。 (为了解决第一个评论,下面,让我们说的编译器符号叫做弗雷德)

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.)

这问题
[的Conditional参考]
让我觉得我可以称为条件的属性添加到上面显示的参考元素,但我不知道是什么值给该属性来实现我想要的东西。

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>Path\To\Dll\NameOfDll.dll</HintPath>
</Reference>



选择的符号与众不同的名字。不是东西,也能像调试或跟踪另一个常量的子串。

Pick a distinctive name for the symbol. Not something that could be a substring of another constant like Debug or Trace.

这篇关于如何有条件地引用基于一个编译符号一个DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆