34

I have a web application project which utilises a set of 3rd party dll's. The issue is that the dev/staging environment is 32bit, but production is 64bit. As such, we have to re-reference and build the solution each time we want to deploy. I am now wanting to automate this, but unsure how to go about it with MSBuild?

All other dll's are the same, just the 3 3rd party dll's.


EDIT

I have made some headway, however am coming up with some runtime assembly issues.

I have 3 dll files, 1.dll, 2.dll, 3.dll. The file version is 5.1 for each. For the 64 bit dlls, the names are exactly the same, just difference file versions. What I have done, is renamed each one to 1.v5.dll, 1.v6.dll etc. In my project files, I am then referencing each dll as follows:

<Reference Include="1.v5.dll" Condition="'$(Platform)'=='x86'">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>bin\1.v5.dll</HintPath>
  <Private>False</Private>
</Reference>
<Reference Include="1.v6.dll" Condition="'$(Platform)'=='x64'">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>bin\1.v6.dll</HintPath>
  <Private>False</Private>
</Reference>

This works in Visual Studio IDE, and my solution compiles file, however when I go to run the website, I get the following error...

"Could not load file or assembly '1.v5' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

Any thoughts on how to approach this?

mickyjtwin
  • 4,960
  • 13
  • 58
  • 77
  • Realizing it doesn't answer your question but... why on earth would you do such a thing; especially in your staging environment? – dkackman Jan 05 '10 at 02:53
  • Our local and staging environments are 32bit machines, and the solution needs to be compiled with the 32bit dll's. In our code, each dll(API) has different functionalities. Our production environment however, is 64 bit, so the solution needs to be compiled with the 64 bit dll's, and those files are copied up to the production box. Each time we want to do this, we had to delete, and re-reference the 32/64 bit dll's, which wasn't difficult, just a pain to do. Automating this would be great! – mickyjtwin Jan 05 '10 at 03:26
  • the dll load problem occurs because you renamed the dll, see http://msdn.microsoft.com/en-us/library/yx7xezcf.aspx for example – stijn Jan 05 '10 at 08:44

2 Answers2

39

You can create conditional references in the project file like this:

<Reference Include="32bit.dll" Condition="'$(Platform)'=='x86'"/>
<Reference Include="64bit.dll" Condition="'$(Platform)'=='x64'"/>

To use this inside VS, you have to create two solution platforms: one for the x86 target and one for the x64 target. Depending on the active platform one of the dlls will be selected, no need for re-referencing.

To automate this using msbuild, create a new project file that builds the other project file a number of times, each time for a different platform/configuration/...:

<Target Name="BuildAll">
  <MSBuild Targets="myproject.proj" Properties="Platform=x86;Configuration=Debug"/>
  <MSBuild Targets="myproject.proj" Properties="Platform=x64;Configuration=Debug"/>
  <MSBuild Targets="myproject.proj" Properties="Platform=x64;Configuration=Release"/>
</Target>

Have a look at the MSBuild task reference for aditional options like building in parallel.

stijn
  • 34,664
  • 13
  • 111
  • 163
  • I've created two solution platforms, x86, and x64. I have also added both versions of the dll's to the bin folder. When I edit the project file, and reload, the references are not found. Not sure why? I cannot add the .dll to the Include value. I can add the hintpath, but still does not get the reference. – mickyjtwin Jan 04 '10 at 23:41
  • I've started to make some progress, however still have issues. I have added to my main question. – mickyjtwin Jan 05 '10 at 02:45
20

This is what I have figured out, and seems to work no problems.

I have created 2 solution platforms, x86 and x64. I have created a new folder in my solution directory called "References", and created n x86 and x64 folder: \References\x86\ \References\x64\ The 3 dll's for each are then placed in their respective directories.

In each project's file, I have then added the following references:

<Reference Include="{Reference1}" Condition="'$(Platform)'=='x86'">
  <HintPath>..\References\dlls\x86\{Reference1}.dll</HintPath>
</Reference>
<Reference Include="{Reference2}" Condition="'$(Platform)'=='x64'">
  <HintPath>..\References\dlls\x64\{Reference2}.dll</HintPath>
</Reference>

Now, when I develop within the IDE, I am working the the relevant dll specific to my needs.

I have then just added a post-build event which copies the dll based on the $(Platform) variable into the bin directory.

mickyjtwin
  • 4,960
  • 13
  • 58
  • 77
  • 6
    since your HintPath contains the platform name anyway, replace it with `.\References\dlls\$(Platform)\...` for maximum maintainability – stijn Mar 14 '13 at 20:47
  • Very nice, thanks. But I have to say that Visual Studio should make this easier for us. What a heck... – Pedro77 Feb 18 '14 at 14:38