为什么在使用命令 Update-Package --reinstall 后安装了新包

Why are new packages been installed after using command Update-Package --reinstall

我有一个解决方案,其中的 nuget 包很少。

这些包引用了不同的网络框架。例如。很少有人以 net451 为目标,一些以 net452 为目标,一些以 net461 为目标。

我的项目有 net461 框架。所以我使用命令 Update-Package --reinstall 重新安装针对 net461 框架的包。

成功了,但我不确定为什么添加的包比我已经添加的还要多?

更新我的包之前。

<package id="EnterpriseLibrary.Common" version="6.0.1304.0" targetFramework="net451" />
  <package id="EnterpriseLibrary.TransientFaultHandling" version="6.0.1304.0" targetFramework="net451" />
  <package id="EnterpriseLibrary.TransientFaultHandling.Caching" version="6.0.1304.0" targetFramework="net451" />
  <package id="EnterpriseLibrary.TransientFaultHandling.Configuration" version="6.0.1304.0" targetFramework="net451" />
  <package id="EnterpriseLibrary.TransientFaultHandling.Data" version="6.0.1304.1" targetFramework="net451" />
  <package id="EnterpriseLibrary.TransientFaultHandling.ServiceBus" version="6.0.1304.0" targetFramework="net451" />
  <package id="EnterpriseLibrary.TransientFaultHandling.WindowsAzure.Storage" version="6.0.1304.0" targetFramework="net451" />
  <package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net451" />
  <package id="Microsoft.Data.Edm" version="5.8.2" targetFramework="net452" />
  <package id="Microsoft.Data.OData" version="5.8.2" targetFramework="net452" />
  <package id="Microsoft.Data.Services.Client" version="5.8.2" targetFramework="net452" />
  <package id="Microsoft.Extensions.DependencyInjection" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net452" />
  <package id="NETStandard.Library" version="1.6.1" targetFramework="net452" />
  <package id="Newtonsoft.Json" version="8.0.2" targetFramework="net452" />
  <package id="System.Collections" version="4.3.0" targetFramework="net452" />
  <package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net452" />
  <package id="System.ComponentModel" version="4.3.0" targetFramework="net452" />
  <package id="System.ComponentModel.EventBasedAsync" version="4.0.11" targetFramework="net452" />
  <package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net452" />
  <package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net452" />
  <package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net452" />
  <package id="System.Dynamic.Runtime" version="4.0.0" targetFramework="net452" />
  <package id="System.Globalization" version="4.3.0" targetFramework="net452" />
  <package id="System.IO" version="4.3.0" targetFramework="net452" />
  <package id="System.IO.Compression" version="4.3.0" targetFramework="net452" />
  <package id="System.Linq" version="4.3.0" targetFramework="net452" />
  <package id="System.Linq.Expressions" version="4.3.0" targetFramework="net452" />
  <package id="System.Linq.Queryable" version="4.0.0" targetFramework="net452" />
  <package id="System.Net.Http" version="4.3.0" targetFramework="net452" />
  <package id="System.Net.Primitives" version="4.3.0" targetFramework="net452" />
  <package id="System.Net.Requests" version="4.0.11" targetFramework="net452" />
  <package id="System.ObjectModel" version="4.3.0" targetFramework="net452" />
  <package id="System.Reflection" version="4.3.0" targetFramework="net452" />
  <package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net452" />
  <package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net452" />
  <package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net452" />
  <package id="System.Runtime" version="4.3.0" targetFramework="net452" />
  <package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net452" />
  <package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net452" />
  <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net452" />
  <package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net452" />
  <package id="System.Spatial" version="5.8.2" targetFramework="net452" />
  <package id="System.Text.Encoding" version="4.3.0" targetFramework="net452" />
  <package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net452" />
  <package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net452" />
  <package id="System.Threading" version="4.3.0" targetFramework="net452" />
  <package id="System.Threading.Tasks" version="4.3.0" targetFramework="net452" />
  <package id="System.Threading.Timer" version="4.3.0" targetFramework="net452" />
  <package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net452" />
  <package id="System.Xml.XDocument" version="4.3.0" targetFramework="net452" />
  <package id="WindowsAzure.Storage" version="8.1.1" targetFramework="net452" />

更新我的包后

<package id="EnterpriseLibrary.Common" version="6.0.1304.0" targetFramework="net461" />
  <package id="EnterpriseLibrary.TransientFaultHandling" version="6.0.1304.0" targetFramework="net461" />
  <package id="EnterpriseLibrary.TransientFaultHandling.Caching" version="6.0.1304.0" targetFramework="net461" />
  <package id="EnterpriseLibrary.TransientFaultHandling.Configuration" version="6.0.1304.0" targetFramework="net461" />
  <package id="EnterpriseLibrary.TransientFaultHandling.Data" version="6.0.1304.1" targetFramework="net461" />
  <package id="EnterpriseLibrary.TransientFaultHandling.ServiceBus" version="6.0.1304.0" targetFramework="net461" />
  <package id="EnterpriseLibrary.TransientFaultHandling.WindowsAzure.Storage" version="6.0.1304.1" targetFramework="net461" />
  <package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net461" />
  <package id="Microsoft.Data.Edm" version="5.8.2" targetFramework="net461" />
  <package id="Microsoft.Data.OData" version="5.8.2" targetFramework="net461" />
  <package id="Microsoft.Data.Services.Client" version="5.8.2" targetFramework="net461" />
  <package id="Microsoft.Extensions.DependencyInjection" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net461" />
  <package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net461" />
  <package id="NETStandard.Library" version="1.6.1" targetFramework="net461" />
  <package id="Newtonsoft.Json" version="8.0.2" targetFramework="net461" />
  <package id="System.AppContext" version="4.3.0" targetFramework="net461" />
  <package id="System.Collections" version="4.3.0" targetFramework="net461" />
  <package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" />
  <package id="System.ComponentModel" version="4.3.0" targetFramework="net461" />
  <package id="System.ComponentModel.EventBasedAsync" version="4.0.11" targetFramework="net461" />
  <package id="System.Console" version="4.3.0" targetFramework="net461" />
  <package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net461" />
  <package id="System.Diagnostics.DiagnosticSource" version="4.3.0" targetFramework="net461" />
  <package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net461" />
  <package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net461" />
  <package id="System.Dynamic.Runtime" version="4.0.0" targetFramework="net461" />
  <package id="System.Globalization" version="4.3.0" targetFramework="net461" />
  <package id="System.Globalization.Calendars" version="4.3.0" targetFramework="net461" />
  <package id="System.IO" version="4.3.0" targetFramework="net461" />
  <package id="System.IO.Compression" version="4.3.0" targetFramework="net461" />
  <package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="net461" />
  <package id="System.IO.FileSystem" version="4.3.0" targetFramework="net461" />
  <package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net461" />
  <package id="System.Linq" version="4.3.0" targetFramework="net461" />
  <package id="System.Linq.Expressions" version="4.3.0" targetFramework="net461" />
  <package id="System.Linq.Queryable" version="4.0.0" targetFramework="net461" />
  <package id="System.Net.Http" version="4.3.0" targetFramework="net461" />
  <package id="System.Net.Primitives" version="4.3.0" targetFramework="net461" />
  <package id="System.Net.Requests" version="4.0.11" targetFramework="net461" />
  <package id="System.Net.Sockets" version="4.3.0" targetFramework="net461" />
  <package id="System.ObjectModel" version="4.3.0" targetFramework="net461" />
  <package id="System.Reflection" version="4.3.0" targetFramework="net461" />
  <package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net461" />
  <package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net461" />
  <package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net461" />
  <package id="System.Runtime" version="4.3.0" targetFramework="net461" />
  <package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net461" />
  <package id="System.Runtime.Handles" version="4.3.0" targetFramework="net461" />
  <package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net461" />
  <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
  <package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net461" />
  <package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" />
  <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" />
  <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" />
  <package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" />
  <package id="System.Spatial" version="5.8.2" targetFramework="net461" />
  <package id="System.Text.Encoding" version="4.3.0" targetFramework="net461" />
  <package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net461" />
  <package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net461" />
  <package id="System.Threading" version="4.3.0" targetFramework="net461" />
  <package id="System.Threading.Tasks" version="4.3.0" targetFramework="net461" />
  <package id="System.Threading.Timer" version="4.3.0" targetFramework="net461" />
  <package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net461" />
  <package id="System.Xml.XDocument" version="4.3.0" targetFramework="net461" />
  <package id="WindowsAzure.Storage" version="8.1.1" targetFramework="net461" />

But i am not sure why there are more packages been added then i already had?

这是 NuGet 默认行为。当我们将nuget包安装到项目中时,nuget也会将其依赖添加到项目中。

添加更多包的原因当它们针对不同的框架时,依赖项是不同的。当您以 .net461 为目标时,一些包将向项目引入更多依赖项。所以添加了比你已经拥有的更多的包。

例如,您可以检查软件包 Microsoft.Extensions.DependencyInjectionSystem.Net.HttpSystem.Runtime.InteropServices 的依赖关系:

显然,当您使用命令 Update-Package -reinstall 重新安装针对 net461 框架的包时,这些包将向项目添加一些新的依赖项。

希望这对您有所帮助。