Jaxidian
Jaxidian

Reputation: 13509

CSProj Conditionals for different DLLs triggered by build configurations

I'm attempting to modify my .csproj files to handle some native and (managed) wrapper assemblies based upon the targeted build configuration (specifically $(Platform)). A specific example (though not the only one) is I'm using Oracle.DataAccess which comes mutually exclusively targeting 32-bit or 64-bit, but not both. Additionally, it has dependencies on 32-bit and 64-bit (respectively) native DLLs. This example creates a problem for me. The reason I want this triggered based on the build configuration is because we are frequently having to switch back and forth for a variety of reasons.

Problem: I include the native DLLs by having them in a project's root directory (as a linked file pointing to a lib folder), flagging them as Content with AlwaysCopy set. This results in them being copied to my bin folder as desired. I attempted to do this by having two ItemGroup blocks with Condition="'$(Platform)' == 'x86'" (and x64) but this seems to not work as I get build errors saying "The file ..\packages\OracleClient\64BitNativeDrivers\xxx.dll' could not be added to the project. There is already a file of the same name in this folder.", even after a very thorough cleaning of the solution's artifacts.

Code snippet:

  <ItemGroup Condition="'$(Platform)' == 'x86'">
    <Content Include="..\packages\OracleClient\32BitNativeDrivers\oci.dll">
      <Link>oci.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\packages\OracleClient\32BitNativeDrivers\oraociicus11.dll">
      <Link>oraociicus11.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\packages\OracleClient\32BitNativeDrivers\OraOps11w.dll">
      <Link>OraOps11w.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup Condition="'$(Platform)' == 'x64'">
    <Content Include="..\packages\OracleClient\64BitNativeDrivers\oci.dll">
      <Link>oci.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\packages\OracleClient\64BitNativeDrivers\oraociicus11.dll">
      <Link>oraociicus11.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\packages\OracleClient\64BitNativeDrivers\OraOps11w.dll">
      <Link>OraOps11w.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

I've tried playing around with a few possibilities here but it seems I'm misunderstanding how to do this properly and I could really use some help.

Thanks!!

Upvotes: 0

Views: 1005

Answers (1)

granadaCoder
granadaCoder

Reputation: 27906

Did you try putting the filter

Condition="'$(Platform)' == 'x86'"

on the <Content> tag ?

Upvotes: 1

Related Questions