Visual Studio Project: How to include a reference for one configuration only?(Visual Studio 项目:如何仅包含一种配置的参考?)
问题描述
环境:VS2008 C# 项目
Env.: VS2008 C# project
我需要构建我的应用程序以在 2 个不同的环境中使用.在其中一种环境中,我需要使用第 3 方 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.
我可以使用#if 块隔离使用此 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 项目:如何仅包含一种配置的参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Visual Studio 项目:如何仅包含一种配置的参考?


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01