NuGet 中的输入字符串格式不正确异常

Input string was not in a correct format exception in NuGet

我正在尝试在我的一个项目中安装 Ninject,并给出了确切的版本和项目名称。我正在使用本地托管的包存储库。我在软件包安装过程中遇到以下问题:

PM> Install-Package Ninject -version 3.2.2.0 -project My.Project.Name
Installing 'Ninject 3.2.2.0'.
You are downloading Ninject from Ninject Project Contributors, the license agreement to which is available at https://github.com/ninject/ninject/raw/master/LICENSE.txt. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'Ninject 3.2.2.0'.
Adding 'Ninject 3.2.2.0' to My.Project.Name.
Install failed. Rolling back...
Install-Package : Input string was not in a correct format.
At line:1 char:16
+ Install-Package <<<<  Ninject -version 3.2.2.0 -project My.Project.Name
    + CategoryInfo          : NotSpecified: (:) [Install-Package], FormatException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

PM> $error[0].Exception.StackTrace
   at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
   at System.String.Format(IFormatProvider provider, String format, Object[] args)
   at NuGet.PowerShell.Commands.NuGetBaseCommand.Log(MessageLevel level, String message, Object[] args)
   at NuGet.VisualStudio.VsProjectSystem.RemoveReference(String name)
   at NuGet.ProjectManager.RemovePackageReferenceFromProject(IPackage package)
   at NuGet.ProjectManager.Execute(PackageOperation operation)
   at NuGet.ProjectManager.Execute(IPackage package, IPackageOperationResolver resolver)
   at NuGet.ProjectManager.RemovePackageReference(IPackage package, Boolean forceRemove, Boolean removeDependencies)
   at NuGet.VisualStudio.VsPackageManager.RollbackProjectActions(IProjectManager projectManager, IEnumerable`1 packagesAdded, IEnumerable`1 packagesRemoved)
   at NuGet.VisualStudio.VsPackageManager.RunProjectAction(IProjectManager projectManager, Action action)
   at NuGet.VisualStudio.VsPackageManager.AddPackageReference(IProjectManager projectManager, IPackage package, Boolean ignoreDependencies, Boolean allowPrereleaseVersio
ns)
   at NuGet.VisualStudio.VsPackageManager.<>c__DisplayClass8.<InstallPackage>b__4()
   at NuGet.VisualStudio.VsPackageManager.RunSolutionAction(Action action)
   at NuGet.VisualStudio.VsPackageManager.InstallPackage(IProjectManager projectManager, String packageId, SemanticVersion version, Boolean ignoreDependencies, Boolean a
llowPrereleaseVersions, Boolean skipAssemblyReferences, ILogger logger)
   at NuGet.VisualStudio.VsPackageManager.InstallPackage(IProjectManager projectManager, String packageId, SemanticVersion version, Boolean ignoreDependencies, Boolean a
llowPrereleaseVersions, ILogger logger)
   at NuGet.PowerShell.Commands.InstallPackageCommand.InstallPackage(IVsPackageManager packageManager)
   at NuGet.PowerShell.Commands.InstallPackageCommand.ProcessRecordCore()
   at NuGet.PowerShell.Commands.NuGetBaseCommand.ProcessRecord()
PM> 

之后:

如何修复?什么会导致此问题?

我不知道究竟是什么导致了这个问题,但我们能够通过 运行 使用管理员凭据执行以下命令来解决它:

regsvr32 "C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\VsLangproj.olb"

但是,请务必以管理员身份实际启动命令行(而不仅仅是 runas),否则您将收到一条 成功 消息,尽管实际上已注册失败。

重启后 Visual Studio 它应该可以工作(至少它对我有用,在几台装有 VS 2010 / 2012 / 2013 的机器上测试过)。

我已经试过了,效果不错。

regsvr32 "C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\VsLangproj.olb"

我发现不需要注册(使用 regsvr 作为管理员)(Win7 64 位,MS Visual Studio Community 2013)。我收到了与 OP 相同的错误消息,但实际上该包已复制到我的解决方案的 "packages" 子文件夹中。我需要做的就是右键单击解决方案,"add references"、"browse" 并找到相应的 dll 文件。