c# - 如何在每个配置的基础上添加程序集引用

标签 c# .net visual-studio visual-studio-2010 windows-phone-7

我目前正在寻找将一些仅用于调试的代码添加到 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 并且忘记了这一点。

首先:使用条件

  1. 创建新项目 DebugOnlyHelpers
  2. 在此项目中引用所有特定于调试的助手
  3. csproj 文件中指定需要过滤引用的条件:

<ProjectReference 
            Include="DebugOnlyHelpers.csproj"
            Condition=" '$(Configuration)' == 'DEBUG' "

第二:ConditionChoose/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/

相关文章:

c# - 为什么在 ConfigurationManager.AppSettings[key] 上调用 .ToString()?

vb.net - Visual Studio 正在扩展构建时包含的通配符项目文件

visual-studio - 将报表查看器 (SSRS) 导出到 Excel 时如何停止文本换行?

c# - Visual Studio 2019 : Insert multiple C++ style single-line comments

c# - ObjectStateManager 不包含引用类型对象的 ObjectStateEntry

c# - 如何确定 FFmpeg 进程何时完成

c# - 是否可以使用非特殊文件夹作为 FolderBrowserDialog 的根文件夹?

c# - Assert.IsTrue(false) 正在通过

c# - 交付静态哈希表的最佳方式 c#

c# - 从字符串中提取值