Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.csproj's platform specific ItemGroup works for assembly references but not content includes?

Since we have three assemblies that come in explicit x86 and x64 versions, I've edited the corresponding .csproj file(s) to use, for example, a block like this:

  <ItemGroup Condition=" '$(Platform)' == 'x86' ">
    <Reference Include="CaliberRMSDK">
      <HintPath>..\Libraries\CaliberRMSDK_IKVM\32bit\CaliberRMSDK.dll</HintPath>
    </Reference>
    <Content Include="..\Libraries\CaliberRMSDK_IKVM\32bit\ikvm-native.dll">
      <Link>ikvm-native.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\Libraries\CaliberRMSDK_IKVM\32bit\JVM.dll">
      <Link>JVM.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup Condition=" '$(Platform)' == 'x64' ">
    <Reference Include="CaliberRMSDK">
      <HintPath>..\Libraries\CaliberRMSDK_IKVM\64bit\CaliberRMSDK.dll</HintPath>
    </Reference>
    <Content Include="..\Libraries\CaliberRMSDK_IKVM\64bit\ikvm-native.dll">
      <Link>ikvm-native.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="..\Libraries\CaliberRMSDK_IKVM\64bit\JVM.dll">
      <Link>JVM.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

When reloading the .csproj file in Visual Studio 2010 and using 'x86' as platform, all works perfectly fine. When choosing 'x64' as platform, the proper 64bit assembly reference is used BUT the linked ( <Content Include= ...> ..) always uses the 32bit ones (and therefore the app is broken).

There's no Any CPU anymore in the project files and I would have 'expected' it to work just fine for the content includes, too.. but it doesn't. Is there anything I am missing?

like image 915
Jörg Battermann Avatar asked Dec 17 '10 12:12

Jörg Battermann


1 Answers

We put the Condition attribute on the Reference element and that works fine. Perhaps the Condition attribute also needs to be added to the Content element? (Do you really need both the Reference element and the Content element?) For example:

<Reference Include="SomeLib" Condition="$(Platform)=='x86'">
  <HintPath>..\..\ThirdParty\SomeLib\clr4\x86\SomeLib.dll</HintPath>
  <Private>False</Private>
</Reference>
<Reference Include="SomeLib" Condition="$(Platform)=='x64' Or $(Platform)=='AnyCPU'">
  <HintPath>..\..\ThirdParty\SomeLib\clr4\x64\SomeLib.dll</HintPath>
</Reference>
like image 164
Ron Avatar answered Nov 11 '22 01:11

Ron