.csproj 的平台特定 ItemGroup 适用于程序集引用,但不适用于内容包含?

发布于 2024-10-08 13:54:19 字数 1696 浏览 0 评论 0原文

由于我们有三个显式 x86 和 x64 版本的程序集,因此我编辑了相应的 .csproj 文件以使用,例如,这样的块:

  <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>

在 Visual Studio 2010 中重新加载 .csproj 文件并使用 ' x86' 作为平台,一切都工作得很好。选择“x64”作为平台时,将使用正确的 64 位程序集引用但是链接的( ..)始终 使用 32 位(因此该应用程序已损坏)。

项目文件中不再有任何 CPU,我“期望”它也能很好地处理包含的内容……但事实并非如此。我有什么遗漏的吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

偏闹i 2024-10-15 13:54:19

我们将 Condition 属性放在 Reference 元素上,效果很好。也许 Condition 属性还需要添加到 Content 元素中? (您真的需要 Reference 元素和 Content 元素吗?)例如:

<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>

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>
亚希 2024-10-15 13:54:19

所以这“只是”一个视觉/显示问题。下面的构建确实使用了正确的引用等,只有 VS2010 显示错误的引用。一切都很好,只是看不见。

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.

π浅易 2024-10-15 13:54:19

那么这个问题有答案了吗?如果没有,我建议切换 ItemGroup 的顺序并查看是否获得相反的结果(它在 x64 中工作,但在 x86 上 Visual Studio 显示错误的引用)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文