Nuget无法安装特定版本

时间:2014-09-29 05:48:33

标签: nuget

我能够设置自己的NuGet服务器(如here所述)。 服务器Packages文件夹包含多个MyPackage版本,例如1.0.8.0和1.0.9.0。 当我以默认方式安装它(没有指定版本)时,它会成功安装。但是当我明确地做

Install-Package MyPackage -Version 1.0.9.0

以下消息出错:

  

Install-Package:无法找到“MyPackage”包的版本“1.0.9.0”。   在行:1字符:16   + install-package<<<< MyPackage -Version 1.0.9.0       + CategoryInfo:NotSpecified:(:) [Install-Package],InvalidOperationException       + FullyQualifiedErrorId:NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

更新 当程序包管理器控制台中的Package Source设置为“全部”时,将显示此错误消息。当我将它设置为我自己的源(事实上,预计会找到包)时,会出现另一个错误:

Install-Package : **There are multiple root elements. Line 42, position 2.**
At line:1 char:16
+ install-package <<<<  dfct.shell.core.contracts -Version "1.0.8.0"
+ CategoryInfo          : NotSpecified: (:) [Install-Package], XmlException
+  FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

多个根元素,第42行?在什么档案? 这是为什么?我认为服务器端存在问题,但无法弄清楚它是什么。

2 个答案:

答案 0 :(得分:5)

原来,MyPackage.1.0.9.0.nupkgMyPackage.1.0.9.0.symbols.nupkg的共存导致NuGet崩溃。 NuGet使用OData作为传输,在OData深处,它无法序列化/反序列化两个包,抱怨“多个根节点”。 所以我只是从-symbols命令行中删除了nuget pack,从而禁用了调试包生成,现在一切正常。

答案 1 :(得分:0)

尝试安装EntityFramework时遇到类似的错误。

PM> Install-Package EntityFramework -Version 6.1.3


Attempting to gather dependency information for package 'EntityFramework.6.1.3' with respect to project 'Project.Data.Entities', targeting '.NETFramework,Version=v4.6.1'
Gathering dependency information took 6,19 ms
Attempting to resolve dependencies for package 'EntityFramework.6.1.3' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'EntityFramework.6.1.3'
Resolved actions to install package 'EntityFramework.6.1.3'
Found package 'EntityFramework 6.1.3' in 'C:\dev\ProjectSource\packages'.
Package 'EntityFramework.6.1.3' already exists in folder 'C:\dev\ProjectSource\packages'
Install failed. Rolling back...
Package 'EntityFramework.6.1.3' does not exist in project 'Project.Data.Entities'
Executing nuget actions took 695,25 ms
Install-Package : There are multiple root elements. Line 22, position 2.
At line:1 char:1
+ Install-Package EntityFramework -Version 6.1.3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Time Elapsed: 00:00:01.1494321

结果证明App.config已损坏,可能是在升级target framework时。现在有两个</configuration>,而<startup>是新的根元素,因此错误为multiple root elements

损坏:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="RabbitMQ.Client" publicKeyToken="89e7d7c5feba84ce" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.6.9.0" newVersion="3.6.9.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>

手动固定版本:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="RabbitMQ.Client" publicKeyToken="89e7d7c5feba84ce" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.6.9.0" newVersion="3.6.9.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>