从 NuGet 安装 SignalR(Newtonsoft.Json 出现问题)

Installing SignalR from NuGet (problems with Newtonsoft.Json)

我正在尝试通过 NuGet 安装 SignalR。当谈到安装 Json 时,它说安装因 PowerShell 策略而失败。 我找到 this post 来解释在这种情况下该怎么做。

很遗憾,我们公司的政策禁止更改设置,我无法更改该值。

我下一步要做的是手动下载 Json.NET 并在我的项目中手动引用。我希望 NuGet 会找到引用并忽略安装。但这并没有奏效。

终于来到我的问题:有没有办法 "tell" NuGet 在安装 SignalR 时忽略 Json.NET 依赖项?

Install-Package 命令有一个忽略依赖项的标志:

Install-Package Microsoft.AspNet.SignalR -IgnoreDependencies

Install-Package [-Id] [-IgnoreDependencies] [-ProjectName ] [-Version ] [-Source ] [-IncludePrerelease] [-Force] [-FileConflictAction] [-DependencyVersion ] [-WhatIf]

-IgnoreDependencies
        Installs only this package and not its dependencies.

        Required: false

more info.

我正要尝试 Sirwan 的建议,直到我意识到由于 PS 的执行策略,我什至无法再 运行 包管理器控制台中的任何命令。

解决方案:

You can actually change the MachinePolcy Execution Policy without going through GPO! You need to go in the registry and edit the following key HKLM:\Software\Policies\Microsoft\Windows\PowerShell and change the ExecutionPolicy value to ByPass

找到解决方案here

这实际上也解决了我安装 Json.NET 时遇到的另一个问题。