我目前正在寻找将一些仅用于调试的代码添加到 Windows Phone 项目中。此调试代码将拖入一些调试类库引用(nunit 帮助器)和一些 WCF 服务客户端引用,我真的不希望在发布版本中引用这些。
任何人都可以建议我可以添加一个 Assembly-Reference 进行调试,但不让它出现在发布中吗?
我在 Connect 上看到过这个 - https://connect.microsoft.com/VisualStudio/feedback/details/106011/allow-adding-assembly-references-on-a-per-configuration-basis-debug-release - 但它被标记为“推迟”
Visual Studio 的 UserVoice 上有一个请求,但它被标记为 Closed
,因为 Won't Fix
这里:https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/2062487-allow-assembly-references-to-switch-based-on-confi
最佳答案
这两种情况都使用 MSBuild Condition
,您已经配置了 csproj
并且忘记了这一点。
首先:使用条件
- 创建新项目 DebugOnlyHelpers
- 在此项目中引用所有特定于调试的助手
- 在
csproj
文件中指定需要过滤引用的条件:
<ProjectReference
Include="DebugOnlyHelpers.csproj"
Condition=" '$(Configuration)' == 'DEBUG' "
第二:将Condition
与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>
关于c# - 如何在每个配置的基础上添加程序集引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7659460/