如何增加汇编参考在每个配置为单位单位、在每个

2023-09-03 06:02:36 作者:知善

目前,我正在寻求增加一些调试只有code到Windows Phone项目。这调试code会拖一些调试类库引用(NUnit的助手)和一些WCF服务客户端的参考,我真的很想没有这些的发行版本引用。

任何人都可以提出任何方式,我可以添加一个汇编参考调试,但又不希望它出现在发布?

我已经看到了这个在连接 - https://connect.microsoft.com/VisualStudio/feedback/details/106011/allow-adding-assembly-references-on-a-per-configuration-basis-debug-release - 但它被标记为延期

解决方案

使用的MSBuild 条件两种情况,你一旦配置的csproj ,而忘记了这一点。

第一:使用条件

创建新项目DebugOnlyHelpers 引用的所有调试特定于该项目的帮手 指定的的csproj 文件一种情况需要过滤引用:

 < ProjectReference
            包括=DebugOnlyHelpers.csproj
            条件='$(配置)'=='DEBUG'
 

二:使用条件与选择/当:

 <选择>
    <当条件='$(配置)'=='DEBUG'>
        < ItemGroup>
             <参考包括=NUnit.dll/>
             <参考包括=Standard.dll/>
         < / ItemGroup>
    < /当>
    <否则>
         < ItemGroup>
             <参考包括=Standard.dll/>
         < / ItemGroup>
    < /否则>
< /选择>
 

最新企业管理法规汇编 续一

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>