开发者

How to add Assembly-References on a per-configuration-basis

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-con开发者_如何学Cfiguration-basis-debug-release - but it's marked as "postponed"

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


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

First: Using Condition

  1. Create new project DebugOnlyHelpers
  2. Reference all Debug-specific helpers in this project
  3. 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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜