Link Building .NET Configuration Depends

I have several configurations with my application to create assemblies for debugging / release, as well as 32-bit and 64-bit assemblies. Now with 32 and 64-bit assemblies, I will need to refer to different DLLs (namely, the assembly with x86 and those built on x64), but the links seem to be global for my project and do not depend on the configuration. Now I always have to exchange links when switching from a 32-bit to a 64-bit assembly (and vice versa). What is the appropriate way to get different links for different configurations?

+4
visual-studio
source share
3 answers

This can be done with a little manual project file management.

First you need to right-click on the project and click "Unload project". Then right-click it and select "Edit" [project name].

When it is loaded into the editor, you will see various entries for your reflections:

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

Note that they are inside the ItemGroup node. Now you can do a little magic ... add an expression to your ItemGroup so that it is used only if the assembly configuration has a certain bit size:

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

Please note: there is no way to do this through the user interface, so you will have to manually manage these link lists (for example, if you need to add another link).

Also note that this is not a hack ... it just uses one of the MSBuild functions (which VS uses to build its projects). You can have as many ItemGroup lists as you want using any expression you like - if it does not have an expression, it will always be included in the assembly.

+2
source share

You can make any section of your csproj conditional on the configuration and / or platform so that you can place your links inside separate sections. Please note: I think this will force a rebuild every time, even if there are no changes, since VS can no longer be sure that a rebuild is required. This may not be a problem, but it will add compile time.

eg.

 <ItemGroup Condition=" '$(Platform)' == 'x86' " > <Reference ...86bit DLL... > </ItemGroup> <ItemGroup Condition=" '$(Platform)' == 'x64' " > <Reference ...64bit DLL... > </ItemGroup> 

I think that you can alternatively make a conditional clue clue path if there is nothing in between the signature, but I can’t remember.

+1
source share

Consider using assembly bindings at runtime

http://msdn.microsoft.com/en-us/library/twy1dw1e.aspx

This will replace your assemblies with those defined in the binding based on the settings.

0
source share

All Articles