You can add conditions to the .csproj
(or .vbproj
) file by editing it by hand.
- Save any work in the project.
- Right-click the project node in solution explorer, and click
Unload Project
.
- The whole project will collapse into a single node. Right click that node and select
Edit <Project Name>.csproj
(or .vbproj
).
Scroll down and look for your DLL that you used for. It should look something like:
<ItemGroup>
<Content Include="bin\Release\x86\My.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
Duplicate it and add a condition. In this case, you want to change it based on platform. Here is one way to do that. Do note that you should analyze the project file to determine the best condition to add for your particular configuration. You should also change the directory to match the (relative) location of your 32 and 64 bit DLL files.
<ItemGroup Condition=" '$(PlatformTarget)' == 'x86' ">
<Content Include="bin\$(Configuration)\x86\My.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup Condition=" '$(PlatformTarget)' == 'x64' ">
<Content Include="bin\$(Configuration)\x64\My.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
Visual Studio doesn't display this correctly (it will show a broken DLL link and a valid DLL link), but rest assured this method functions. It also helps to understand that a Visual Studio project file is nothing more than an MSBuild configuration file. So, although Visual Studio doesn't support a way to add or display conditions or some other MSBuild options, they all will function correctly if configured according to the MSBuild documentation.