18

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?

starblue
  • 55,348
  • 14
  • 97
  • 151
Jörg Battermann
  • 4,044
  • 5
  • 42
  • 79
  • Did you turn on the msbuild verbose log and see what's going on? – Harvey Kwok Dec 20 '10 at 06:42
  • I have tested it with a blank project, and it actually works. It's supposed to, as stated here: http://msdn.microsoft.com/en-us/library/ms171468(v=VS.100).aspx ("Visual Studio looks at the conditions on PropertyGroup, ItemGroup, Import, property, and item elements..."). Note the *Content* tag means the file is a static one, so you won't be able to use it otherwise. Maybe you wanted to use it as a reference DLL? This won't work, allright. – Simon Mourier Dec 20 '10 at 17:40
  • Hrm... the JVM.dll up there is not an assembly reference but a native one that contains functions that are p/invoke'ed and hence the CopyToOutputDirectory etc. Basically it's just a file I reference in the .csproj which shall be copied over to the build output directory (but in my case it depends on the arch which one to use). The assembly reference ones work fine in my case, only those 'referenced'/project arch-specific reference files do not. Will have to check tomorrow morning whether the msbuild log contains anything that might tell me more. – Jörg Battermann Dec 20 '10 at 20:01
  • 1
    As it turns out msbuild -does- use the correct Content Include'ed .dll (thanks for the tip regarding checking the msbuild log), Visual Studio 2010 just doesn't display the reference correctly. – Jörg Battermann Dec 21 '10 at 11:20

3 Answers3

2

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>
Ron
  • 1,888
  • 20
  • 25
  • Thanks @Ron never knew you could use condition on reference itself. Works like a charm! – JMIII Jun 02 '21 at 13:53
1

So this is 'only' a visual / display problem. Underneath builds do use the proper references etc, only VS2010 displays the wrong one. All good, just not visible.

Jörg Battermann
  • 4,044
  • 5
  • 42
  • 79
0

So has this question been answered? If not, I would recommend switching the order of the ItemGroups and seeing if the opposite result is achieved (that it works in x64 but on x86 Visual Studio displays the wrong reference).

Michael
  • 1,786
  • 5
  • 23
  • 42