使.NET参考配置依赖 [英] Making .NET References Configuration dependant

查看:95
本文介绍了使.NET参考配置依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个配置与我的应用程序,使调试/发行版本,也是32位和64位版本。现在有32位和64位建立我需要引用不同的DLL(即那些建立与x86和那些建立与64位),但引用似乎是全球为我的项目,不依赖于配置。现在,我一直都当我从32位切换到64位版本(反之亦然)交换引用。什么是适当的方式,以实现不同的配置不同的参考?

I have several configurations with my app to make debug/release builds and also 32 bit and 64 bit builds. Now with 32 and 64 bit builds I would need to reference different dlls (namely those build with x86 and those build with x64) but the references seem to be global for my project and don't depend on the configuration. Now I always have to exchange the references when I switch from 32 bit to 64 bit build (and vice versa). What is the appropriate way to achieve different references for different configurations?

推荐答案

这可以用手工操作的项目文件的一点点做。

This can be done with a little bit of manual manipulation of the project files.

首先,你需要右键单击该项目,然后单击卸载项目的。然后右键就可以再次单击并选择的修改[项目名称] 的。

First you need to right click on the project, and click Unload Project. Then right click on it again and select Edit [project name].

当它在编辑器中加载,你会看到不同的条目为您refences:

When it is loaded in the editor you will see various entries for your refences:

<ItemGroup>
    <Reference Include="System.Xml" />
    <Reference Include="WindowsBase">
        <RequiredTargetFramework>3.0</RequiredTargetFramework>
    </Reference>
    <Reference Include="PresentationCore">
        <RequiredTargetFramework>3.0</RequiredTargetFramework>
    </Reference>
    <Reference Include="PresentationFramework">
        <RequiredTargetFramework>3.0</RequiredTargetFramework>
    </Reference>
    <Reference Include="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
        <SpecificVersion>False</SpecificVersion>
        <HintPath>..\Common\Lib\3rdParty\Prism\4.0\Desktop\Microsoft.Practices.ServiceLocation.dll</HintPath>
    </Reference>
</ItemGroup>

请注意,这些是一个 ItemGroup 节点中。 您现在可以进行小魔术......添加一个前pression您ItemGroup使得它只能应用在构建配置是有一定的位数:

Note that these are inside an ItemGroup node. You can now perform a little magic... add an expression to your ItemGroup so that it is only used if the build configuration is a certain bitness:

<ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    <!-- these are the references used when there is a Release x86 build -->
    <Reference Include="System.Xml" />
</ItemGroup>

请注意,有没有办法通过UI要做到这一点,所以你必须手动管理这些引用列表(例如,如果你需要添加另一个参考)。

Note that there is no way to do this through the UI, so you will have to manually manage these reference lists (e.g. if you need to add another reference).

另外请注意,这不是一个黑客......它只是利用的的MSBuild 的功能(这是由VS来构建项目)。你可以有很多这样的 ItemGroup 像使用任何EX pression你喜欢的名单,你 - 如果它不具有前pression然后它会总是包含在构建中。

Also note that this is not a hack... it is simply utilising one of the features of MSBuild (which is used by VS to build your projects). You can have as many of these ItemGroup lists as you like using any expression you like - if it doesn't have an expression then it will always be included in the build.

这篇关于使.NET参考配置依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆