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

时间:2022-09-01 16:40:39

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.

我目前正在寻找一些只调试代码到Windows Phone项目。这个调试代码将拖入一些调试类库引用(nunit helpers)和一些WCF服务客户端引用,我真的希望在发布版本中没有这些引用。

Can anyone suggest any way that I can add an Assembly-Reference to debug, but not have it appear in release?

任何人都可以建议我可以添加一个Assembly-Reference来调试,但不会让它出现在发布中吗?

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"

我在Connect上看过这个 - https://connect.microsoft.com/VisualStudio/feedback/details/106011/allow-adding-assembly-references-on-a-per-configuration-basis-debug-release-但它是标记为“推迟”

There's a request on Visual Studio's UserVoice but it is marked as Closed as Won't Fix here: https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/2062487-allow-assembly-references-to-switch-based-on-confi

在Visual Studio的UserVoice上有一个请求,但它被标记为已关闭,因为这里不会修复:https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/2062487-allow-assembly-references-到交换机基于-ON-CONFI

2 个解决方案

#1


13  

Both cases using MSBuild Condition, you've once configure csproj and forget about this.

两种情况都使用MSBuild Condition,你曾经配置过csproj而忘记了这一点。

First: Using Condition

第一:使用条件

  1. Create new project DebugOnlyHelpers
  2. 创建新项目DebugOnlyHelpers

  3. Reference all Debug-specific helpers in this project
  4. 引用此项目中所有特定于Debug的帮助程序

  5. Specify a Condition in csproj file where need to filter references:
  6. 在csproj文件中指定需要过滤引用的条件:


<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>

#2


-5  

Unfortunately there's no way to do this right now. You'll have to switch to debug and remove the reference, then add it back when you return to release.

不幸的是,现在没办法做到这一点。您必须切换到debug并删除引用,然后在返回发行版时将其添加回来。

#1


13  

Both cases using MSBuild Condition, you've once configure csproj and forget about this.

两种情况都使用MSBuild Condition,你曾经配置过csproj而忘记了这一点。

First: Using Condition

第一:使用条件

  1. Create new project DebugOnlyHelpers
  2. 创建新项目DebugOnlyHelpers

  3. Reference all Debug-specific helpers in this project
  4. 引用此项目中所有特定于Debug的帮助程序

  5. Specify a Condition in csproj file where need to filter references:
  6. 在csproj文件中指定需要过滤引用的条件:


<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>

#2


-5  

Unfortunately there's no way to do this right now. You'll have to switch to debug and remove the reference, then add it back when you return to release.

不幸的是,现在没办法做到这一点。您必须切换到debug并删除引用,然后在返回发行版时将其添加回来。