Visual Studio项目:如何以包括只有一个配置的参考? [英] Visual Studio Project: How to include a reference for one configuration only?

查看:260
本文介绍了Visual Studio项目:如何以包括只有一个配置的参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

信封:VS2008 C#项目

Env.: VS2008 C# project

我需要建立我的应用程序在2个不同的环境中使用。在这些环境中的一个,我需要使用第三方DLL组件。

I need to build my app for use in 2 different environments. In one of those environments, I need to use a 3rd party DLL assembly.

我可以隔离使用使用#如果阻止此DLL的代码。可是我怎么有条件包括参考的CS项目文件中的DLL

I could isolate the code that uses this DLL using #if blocks. But how do I conditionally include the reference to the DLL in the CS project file?

编辑:womp在他的评论的好点。我变成了单独的问题:请问参考DLL在所有如果它从来没有被称为加载?
TIA,

womp has a good point in his comment. I turned into a separate question: Will the referenced DLL be loaded at all if it's never called? TIA,

推荐答案

卸载该项目,并打开它.XML

Unload the project and open it as .XML

找到参考的项目标签,并添加一个条件属性。

Locate the reference item tag and add a Condition attribute.

例如:

<ItemGroup>
  <Reference Include="System.Core">
    <RequiredTargetFramework>3.5</RequiredTargetFramework>
  </Reference>
  <Reference Include="System.Data" />
  <Reference Include="System.Drawing" />
  <Reference Include="System.Xml" />

  <Reference Include="MyUtilities.Debug"
    Condition="'$(Configuration)'=='Debug'"/>

</ItemGroup>



注意最后一个引用现在有一个条件。

Notice the last reference now has a condition.

这篇关于Visual Studio项目:如何以包括只有一个配置的参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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