問題描述
環境: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 項目:如何僅包含一種配置的參考?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!