首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NuGet选择了错误的DLL (32位与64位)

NuGet选择了错误的DLL (32位与64位)
EN

Stack Overflow用户
提问于 2021-06-12 03:37:09
回答 1查看 34关注 0票数 0

我使用的是一个.net NuGet,它包含一个编译成本机代码的DLL。本机DLL有两个版本,32位版本和64位版本。

nuget使用其"build“文件夹中的".targets”文件来确定要复制的DLL。目标文件如下所示:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- Ensure that for Framework projects the correct DLL is copied to the build directory -->
  
  <ItemGroup Condition=" '$(Platform)' == 'x64' OR '$(Platform)' == 'AnyCPU' ">
    <Content Include="$(MSBuildThisFileDirectory)..\runtimes\win-x64\native\FiftyOne.DeviceDetection.Hash.Engine.OnPremise.Native.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Link>FiftyOne.DeviceDetection.Hash.Engine.OnPremise.Native.dll</Link>
    </Content>
  </ItemGroup>

  <ItemGroup Condition=" '$(Platform)' == 'x86' ">
    <Content Include="$(MSBuildThisFileDirectory)..\runtimes\win-x86\native\FiftyOne.DeviceDetection.Hash.Engine.OnPremise.Native.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Link>FiftyOne.DeviceDetection.Hash.Engine.OnPremise.Native.dll</Link>
    </Content>
  </ItemGroup>

</Project>

然而,即使我使用的是64位计算机和64位构建目标,它始终是32位版本最终在我的构建的"Bin“文件夹中。

有谁知道这个过程是如何工作的,以及是什么决定了NuGet将决定以哪个平台为目标?如何使nuget-restore-and-build进程选择64位DLL?(使用Visual Studio或msbuild执行构建)

EN

回答 1

Stack Overflow用户

发布于 2021-06-12 05:47:59

您发布的目标文件与最新版本(4.2.4)的FiftyOne.DeviceDetection.Hash.Engine.OnPremise NuGet软件包的目标文件不匹配,其中AnyCPU匹配的是x86平台,而不是x64平台:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- Ensure that for Framework projects the correct DLL is copied to the build directory -->
  
  <ItemGroup Condition=" '$(Platform)' == 'x64' ">
    <Content Include="$(MSBuildThisFileDirectory)..\runtimes\win-x64\native\FiftyOne.DeviceDetection.Hash.Engine.OnPremise.Native.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Link>FiftyOne.DeviceDetection.Hash.Engine.OnPremise.Native.dll</Link>
    </Content>
  </ItemGroup>

  <ItemGroup Condition=" '$(Platform)' == 'x86' OR '$(Platform)' == 'AnyCPU' ">
    <Content Include="$(MSBuildThisFileDirectory)..\runtimes\win-x86\native\FiftyOne.DeviceDetection.Hash.Engine.OnPremise.Native.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Link>FiftyOne.DeviceDetection.Hash.Engine.OnPremise.Native.dll</Link>
    </Content>
  </ItemGroup>

</Project>

因此,为了让正确的本机dll在您的输出目录中结束,您应该在您的csproj文件中添加<Platform>x64</Platform>,或者通过指定如下Platform属性来构建您的项目:

代码语言:javascript
复制
dotnet build /p:Platform=x64 MyApp.csproj
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67942689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档