添加到我的项目但未被引用的 NuGet 包

NuGet packages added to my project that are not referenced

恢复 NuGet 包时,我看到 Xamarin.ios.CameraViewController 已恢复到我的包及其所有依赖项。但我从未引用过 Xamarin.ios.CameriaViewController 也不是我引用的包的依赖项。

我的 csproj nuget 引用:

<ItemGroup>
<PackageReference Include="Acr.UserDialogs">
  <Version>7.0.3</Version>
</PackageReference>
<PackageReference Include="CarouselView.FormsPlugin">
  <Version>5.2.0</Version>
</PackageReference>
<PackageReference Include="DLToolkit.Forms.Controls.FlowListView">
  <Version>2.0.11</Version>
</PackageReference>
<PackageReference Include="GMImagePicker.Xamarin">
  <Version>2.3.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.Net.Http">
  <Version>2.2.29</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
  <Version>12.0.1</Version>
</PackageReference>
<PackageReference Include="Plugin.FacebookClient">
  <Version>1.4.0</Version>
</PackageReference>
<PackageReference Include="Plugin.FileUploader">
  <Version>1.4.0</Version>
</PackageReference>
<PackageReference Include="Plugin.GoogleClient">
  <Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Remote.Linq.Newtonsoft.Json">
  <Version>5.8.2</Version>
</PackageReference>
<PackageReference Include="Rg.Plugins.Popup">
  <Version>1.1.5.188</Version>
</PackageReference>
<PackageReference Include="SQLite.Net.Async-PCL">
  <Version>3.1.1</Version>
</PackageReference>
<PackageReference Include="SQLite.Net.Core-PCL">
  <Version>3.1.1</Version>
</PackageReference>
<PackageReference Include="Syncfusion.Xamarin.SfAutoComplete">
  <Version>16.4.0.54</Version>
</PackageReference>
<PackageReference Include="Xam.Plugin.Connectivity">
  <Version>3.2.0</Version>
</PackageReference>
<PackageReference Include="Xam.Plugin.Media">
  <Version>4.0.1.5</Version>
</PackageReference>
<PackageReference Include="Xam.Plugins.Forms.ImageCircle">
  <Version>3.0.0.5</Version>
</PackageReference>
<PackageReference Include="Xam.Plugins.Messaging">
  <Version>5.2.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Essentials">
  <Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="3.4.0.1029999" />
<PackageReference Include="System.Reflection.Emit">
  <Version>4.3.0</Version>
  <ExcludeAssets>all</ExcludeAssets>
</PackageReference>
<PackageReference Include="Xamarin.Forms.ImagePicker">
  <Version>1.0.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Google.iOS.SignIn">
  <Version>4.4.0</Version>
</PackageReference>
<PackageReference Include="Xamd.Plugins.Forms.ImageCarousel">
  <Version>1.0.2</Version>
</PackageReference>
<PackageReference Include="Xfx.Controls">
  <Version>1.1.3</Version>
</PackageReference>
</ItemGroup>

那么为什么要引用呢?我怎样才能删除它?

Xamarin.Forms.ImagePicker.iOS的依赖,是Xamarin.Forms.ImagePicker的依赖。

  • 在项目文件中维护包引用,仅 顶级依赖项列在那里,即你有的包 明确添加。
  • 现在,包可以依赖于其他包。这些 package become your transitive dependencies - 你做的包 没有显式添加,但现在你隐式地依赖它们。
  • 大多数时候你不太关心他们,这就是为什么他们不出现在 已安装软件包的列表,即顶级依赖项。
  • 但是,您可以查看所有依赖项,包括传递依赖项 - 打开项目的 obj 目录。您会看到 projects.assetes.json 您会看到类似

    的内容
    "Microsoft.NETCore.UniversalWindowsPlatform/6.2.8": {
     "type": "package",
     "dependencies": {
       "Microsoft.NETCore.Platforms": "2.1.0",
       "Microsoft.Net.Native.Compiler": "2.2.3",
       "Microsoft.Net.UWPCoreRuntimeSdk": "2.2.8",
       "NETStandard.Library": "2.0.3"
    }
    

在那个例子中,Microsoft.NETCore.UniversalWindowsPlatform 是一个你显式安装的包,会在你的 csproj 引用中看到,但它也带来了一堆自己的依赖项,即 Microsoft.NETCore.PlatformsMicrosoft.Net.Native.Compiler,等