本机 NuGet 包安装失败

Native NuGet package installation failure

我创建了两个 NuGet 包:一个本机 (C++) NuGet 包和一个依赖于前者的常规 .NET NuGet 包;并将两者部署到内部 NuGet 存储库。
然后我创建了一个测试 .NET 项目并成功安装了 lead .NET 包,而 PM 也安装了本机包。

接下来,我尝试将 .NET 包安装到实际的消费者 .NET 项目中,安装失败,错误消息为:

Could not install package 'Native 1.0.0'. You are trying to install this package into a project targets '.NETFramework,Version=v4.7.1', but the package does not contain any assembly references or content files that are compatible with that framework.

两个项目(test/successful 和 product/unsuccessful)确实以 .NET v4.7.1 为目标,都以 AnyCPU[=30= 为目标] 并且都使用相同的工具集。

<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <OutputType>Exe</OutputType>
    <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>

我不知道为什么我的包安装会在产品项目中产生上述错误。

预先感谢大家的帮助。

Then I created a test .NET project and successfully installed the lead .NET package, while PM installs the native package as well.

Next, I tried to install the .NET package into an actual consumer .NET project, and the installation failed with the error message:

网上有很多针对此类消息的解决方法the package does not contain any assembly references or content files that are compatible with that framework。对于您的具体问题,由于一个成功,另一个不成功:

  1. 我建议先clean the nuget cache,再做其他检查。因为当您安装或恢复 nuget pakcages 时,它会首先尝试在缓存中找到它。类似问题见 .

  2. 然后确保同一解决方案中的所有项目都使用相同的方式来管理 nuget 包。 (所有 PackageReference 或所有 packages.config)。而对于VS217及更高版本,更推荐packageReference:) 类似问题见.