突然间,升级 Nuget 包时出现此错误。我遇到的所有修复都不起作用。我正在使用 Visual Studio 2013。
'Newtonsoft.Json 6.0.3' 已经安装。将“Newtonsoft.Json 6.0.3”添加到 Tournaments.Notifications。成功将“Newtonsoft.Json 6.0.3”添加到 Tournaments.Notifications。执行脚本文件'F:\My Webs\BasketballTournaments\MainBranch\packages\Newtonsoft.Json.6.0.3\tools\install.ps1'。无法初始化 PowerShell 主机。如果您的 PowerShell 执行策略设置设置为 AllSigned,请先打开包管理器控制台以初始化主机。
包管理器控制台
尝试对“文件系统”提供程序执行 InitializeDefaultDrives 操作失败。
如果我在控制台中等待初始化完成,我可以添加一些包。
将执行策略设置为 RemoteSigned 或 Unrestricted 应该可以工作。它必须在管理员模式下通过 PowerShell 控制台进行更改。请注意,更改将根据 PowerShell 控制台的位版本应用,因此是 32 位或 64 位。因此,如果您想在需要特定策略的 Visual Studio(32 位版本)中安装包,您应该通过 PowerShell (x86) 更改策略设置。
PowerShell(作为管理员)将策略设置为不受限制的命令(如@Gabriel在评论中指出的那样)是:
start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job
将策略设置为无限制后,您需要在安装完成后将策略设置回其原始状态。
请记住在 PowerShell (x86) 中完成 Set-ExecutionPolicy Unrestricted
后重新启动 Visual Studio。
如果这不起作用,请在 PowerShell (x86) 中尝试 Set-ExecutionPolicy RemoteSigned
,然后重新启动 Visual Studio。
默认情况下,出于安全原因,PowerShell 脚本的执行非常有限。为了在 NuGet 中使用,我们需要打开门。
1. 步骤
打开 Windows PowerShell
,作为 Administrator
运行
2. 步骤
NuGet 使用 32 位控制台,因此不会受到 64 位控制台更改的影响。运行以下脚本以确保您正在配置 32 位控制台。
start-job { Set-ExecutionPolicy RemoteSigned } -RunAs32 | wait-job | Receive-Job
3. 步骤
重新启动 Visual Studio
我在“管理 NuGet 包”对话框中遇到了同样的问题,我使用了一种可能对其他人有所帮助的解决方法——从包管理器控制台运行:
如果我使用命令行 powershell commandlet install-package,一切都很好。
我反对更改安全设置“只是为了让它工作”。
Get-Package -Filter PartOfPackageName
搜索已安装的软件包,Install-Package PackageName -Version 7.0.1
安装特定版本的软件包。不要忘记选择 Package Manager Console 顶部的 Default Project
没有答案对我有用。
所有政策都是正确的,但安装软件包时出现错误
无法初始化 PowerShell 主机。如果您的 PowerShell 执行策略设置设置为 AllSigned,请先打开包管理器控制台以初始化主机。
解决方案:我已经卸载了 nuget 包管理器插件并重新安装了它。
以管理员身份运行 Visual Studio 对我有用。
我的 Visual Studio 2015 遇到了这个问题。我再次卸载并重新安装了 NuGet 包管理器。它对我有用。
我更新了 Nuget 包管理器并为我修复了它。
这对我来说最近从 6.0.4 开始发生,我认为这不是一个很好的解决方案,但这对我有帮助。关闭 Visual Studio
以管理员身份打开 Windows PowerShell 提示符(非常重要)并运行以下命令:Set-ExecutionPolicy Bypass 打开 Visual Studio,打开您的解决方案并使用 Nuget 安装 JSON.Net(或任何包含它作为依赖项的包)。一旦一切正常,我建议使用以下命令将 powershell 执行策略设置回受限:Set-ExecutionPolicy Restricted
升级到 Windows 10 后,我遇到了同样的问题。
这对我有用
关闭 Visual Studio 以管理员身份运行 Powershell 以管理员身份运行 Set-ExecutionPolicy Unrestricted 以管理员身份运行 Visual Studio 清理项目并添加 nuget 包
如果仍然不起作用,请尝试编辑 devenv.exe.config
Visual Studio 2013:C:\Users\<UserName>\AppData\Local\Microsoft\VisualStudio\12.0
Visual Studio 2015:C:\Users\<UserName>\AppData\Local\Microsoft\VisualStudio\14.0
添加以下内容
<dependentAssembly>
<assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Utility" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.ConsoleHost" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Management" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Security" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Diagnostics" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
devenv.exe.config
是在 VS2013 和 VS2015 中对我有用的唯一修复。 VS2013:C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\12.0
VS2015:C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\14.0
对我不起作用的是更改执行策略,更改注册表中的执行策略,重新安装包管理器,修复 Visual Studio,重新启动 Visual Studio,重新启动 Windows。
如果以上答案对您有用-
打开运行 - windows + R 打开注册表编辑器 - 键入 regedit.exe 打开 - HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\PowerShell 在右窗格中 - 修改“ExecutionPolicy”并将其“值数据”保留为空白。重新启动您的视觉工作室,现在您的 Powershell 可以正确初始化。
默认情况下,我的 Windows 10 64 位仅启用了 Powershell 1.0 版。我更改了控制面板/程序/程序和功能/关闭 Windows 功能。
确保已启用 Windows Powershell 2.0 引擎。
以非管理员模式重新启动 VS2015,并正确安装所有软件包。
我在 vs2013 上遇到了同样的问题,更改执行策略并没有解决它。我发现的唯一可行的解决方案是从 VS 卸载 Nuget 并重新安装。步骤在这里:https://stackoverflow.com/a/32619961/3853238
关闭所有 Visual Studio 实例,然后重试。它对我有用:)
我需要做的就是重新启动 Visual Studio,打开 NuGet Package Manager Console
,然后使用 Manage NuGet Packages
对话框工作。
在尝试了各种建议的修复后,最终通过更新 Visual Studio 中的 NuGet 包管理器扩展来解决。
这是在工具 -> 扩展和更新下完成的,然后在扩展和更新对话框更新 -> Visual Studio 库中完成。可能需要重新启动 Visual Studio。
有同样的问题,这为我解决了(Powershell 作为管理员):
Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value ByPass
VS2015:更新了 NuGet 并正常工作。
对我来说,诀窍是使用以下链接重新安装 NuGet 包管理器:
与 2013 年相比:https://github.com/NuGet/Home/releases/download/2.8.7/NuGet.Tools.vsix
与 2015 年相比:https://github.com/NuGet/Home/releases/download/3.1.1/NuGet.Tools.vsix
如果上述方法均无帮助,请查看是否可以更新 Visual Studio。
当我尝试安装 Newtonsoft.Json 时,我遇到了与 Visual Studio 2017 社区相同的问题。 ExecutionPolicy
更改没有帮助(我尝试同时使用 PowerShell 和注册表编辑器)。我还尝试卸载和安装 NuGet。
运行 VS2017 安装文件后,它要求更新 Visual Studio。更新后所有问题都消失了。
对我来说,将执行策略设置为 Unrestricted 不起作用。我必须通过进入控制面板来修复 vs2013 安装。修复安装对我有用。
在尝试了所有建议的解决方案后,VS 2015 update 2 没有任何效果
从解决方案文件夹中删除包文件夹并从 Visual Studio 中恢复它对我有用
我有一个类似的问题。我已通过在“打开或关闭 Windows 功能”中打开“Windows PowerShell 2.0”功能来修复它。注意这个功能是默认开启的,我前几天手动关闭的。
我正在使用 Windows 10 Pro 64 位,同样的问题是 Visual Studio 2015 和 2017(32 位和 64 位应用程序)
下载并安装 Administrative Templates for Windows PowerShell
Next: Powershell x86 from As Administrator
Run: Get-ExecutionPolicy -List , and see if you have RemoteSigned etc..
1. 5 different scopes Set-ExecutionPolicy "RemoteSigned" -Scope Process -Confirm:$false
2. Machine and User Policy you have to set through the Group Policy Administration Template in 2 areas.
更新 - 编辑:
Set ALL of them to "Undefined" and ONLY the LocalMachine to "Restricted"
这是在我给予我的 powershell 更多权限后可能修复的问题,但我不知道它会弄乱 Visual Studio 2013 和 2015
此问题并不总是与 PowerShell 执行策略有关。我的机器对 PowerShell x64 和 x86 都配置为“不受限制”,但在 Visual Studio 2013 中我仍然不时收到此错误消息。
当我尝试打开包管理器控制台时:
Windows PowerShell 成功更新了您的执行策略,但该设置被在更具体范围内定义的策略覆盖。由于覆盖,您的 shell 将保留其当前有效的 Unrestricted 执行策略。键入“Get-ExecutionPolicy -List”以查看您的执行策略设置。有关详细信息,请参阅“Get-Help Set-ExecutionPolicy”。
这不是有效的错误消息。
重新启动 Visual Studio 并不总能解决问题。
以管理员身份运行该过程永远不会解决问题。
与 Declan 一样,Package Manager 插件的最新更新修复了该问题:2.8.60723.765
将执行策略设置为 Bypass 而不是 Unrestricted 或 RemoteSigned; this tutorial gives fuller instructions。此外,如果您在使用 PowerShell 更改策略时遇到问题,那么作者将向您展示如何在 Regedit 中更改它。
这里黑暗中的刺伤太多了,所以我会添加我自己的。
就我而言,我还收到一条消息,指出缺少锁定文件,并建议在包管理器控制台中运行 dnu restore
。我这样做了,重新启动了 VS,现在一切正常。
对我有用的是:
将执行策略设置为不受限制。查找模块 ISEModuleBrowserAddon |安装模块导入模块 ISEModuleBrowserAddon 查找模块 ISEScriptAnalyzerAddOn | Install-Module Import-Module ISEScriptAnalyzerAddOn Import-Module ScriptBrowser 在 ISE 中,您需要 Enable-ScriptBrowser
而且您的 ISE 中有模块、脚本和分析器。
在 Win 10 Pro、x64 控制台主机 5.0.10586.122 中运行
祝你好运!
不定期副业成功案例分享
start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job
。