如何增加汇编参考在每个配置为单位 [英] How to add Assembly-References on a per-configuration-basis
问题描述
目前,我正在寻求增加一些调试只有code到Windows Phone项目。这调试code会拖一些调试类库引用(NUnit的助手)和一些WCF服务客户端的参考,我真的很想没有这些的发行版本引用。
任何人都可以提出任何方式,我可以添加一个汇编参考调试,但又不希望它出现在发布?
我已经看到了这个在连接 - <一个href="https://connect.microsoft.com/VisualStudio/feedback/details/106011/allow-adding-assembly-references-on-a-per-configuration-basis-debug-release">https://connect.microsoft.com/VisualStudio/feedback/details/106011/allow-adding-assembly-references-on-a-per-configuration-basis-debug-release - 但它被标记为延期
使用的MSBuild 条件两种情况
,你一旦配置的csproj
,而忘记了这一点。
第一:使用条件
- 创建新项目DebugOnlyHelpers
- 引用的所有调试特定于该项目的帮手
- 指定的
的csproj
文件一种情况需要过滤引用:
&LT; ProjectReference
包括=DebugOnlyHelpers.csproj
条件='$(配置)'=='DEBUG'
二:使用条件
与选择/当:
&LT;选择&GT;
&LT;当条件='$(配置)'=='DEBUG'&GT;
&LT; ItemGroup&GT;
&lt;参考包括=NUnit.dll/&GT;
&lt;参考包括=Standard.dll/&GT;
&LT; / ItemGroup&GT;
&LT; /当&GT;
&LT;否则&GT;
&LT; ItemGroup&GT;
&lt;参考包括=Standard.dll/&GT;
&LT; / ItemGroup&GT;
&LT; /否则&GT;
&LT; /选择&GT;
I'm currently looking to add some debug only code to a windows phone project. This debug code will drag in some debug class library references (nunit helpers) and some WCF service client references, and I'd really like to not have these referenced in the release build.
Can anyone suggest any way that I can add an Assembly-Reference to debug, but not have it appear in release?
I've seen this on Connect - https://connect.microsoft.com/VisualStudio/feedback/details/106011/allow-adding-assembly-references-on-a-per-configuration-basis-debug-release - but it's marked as "postponed"
Both cases using MSBuild Condition
, you've once configure csproj
and forget about this.
First: Using Condition
- Create new project DebugOnlyHelpers
- Reference all Debug-specific helpers in this project
- Specify a Condition in
csproj
file where need to filter references:
<ProjectReference
Include="DebugOnlyHelpers.csproj"
Condition=" '$(Configuration)' == 'DEBUG' "
Second: Using Condition
together with Choose/When:
<Choose>
<When Condition=" '$(Configuration)'=='DEBUG' ">
<ItemGroup>
<Reference Include="NUnit.dll" />
<Reference Include="Standard.dll" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Standard.dll" />
</ItemGroup>
</Otherwise>
</Choose>
这篇关于如何增加汇编参考在每个配置为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!