簡體   English   中英

由於“無法初始化PowerShell主機”,無法安裝nuget包

[英]Can't install nuget package because of “Failed to initialize the PowerShell host”

突然之間,升級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,請打開程序包管理器控制台以首先初始化主機。

包管理器控制台

嘗試在“FileSystem”提供程序上執行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

我在Manage NuGet Packages對話框中遇到了同樣的問題,我使用了一個可以幫助其他人的解決方法 - 從包管理器控制台運行:

如果我使用命令行powershell命令行安裝包,一切都很好。

我不喜歡改變安全設置“只是為了讓它工作”。

沒有答案對我有用。

所有策略都是正確的但我在安裝軟件包時遇到錯誤

無法初始化PowerShell主機。 如果PowerShell執行策略設置設置為AllSigned,請打開程序包管理器控制台以首先初始化主機。

解決方案 :我已經卸載nuget包管理器插件並重新安裝了它。

以管理員身份運行Visual Studio為我工作。

我更新了Nuget包管理器並為我修復了它。

我的Visual Studio 2015出現了這個問題。我再次卸載並重新安裝了NuGet Package Manager。 它對我有用。

最近我開始用6.0.4開始,我不認為這是一個非常好的解決方案,但這對我有幫助。 關閉Visual Studio

  1. 以管理員身份打開Windows PowerShell提示符(非常重要)並運行以下命令:Set-ExecutionPolicy Bypass
  2. 打開Visual Studio,打開解決方案並使用Nuget安裝JSON.Net(或任何包含它作為依賴項的包)。
  3. 一切正常后,我建議使用以下命令將powershell執行策略設置為受限制:Set-ExecutionPolicy Restricted

升級到Windows 10后,我遇到了同樣的問題。

這對我有用

  1. 關閉Visual Studio
  2. 以管理員身份運行Powershell
  3. 運行Set-ExecutionPolicy Unrestricted
  4. 以管理員身份運行Visual Studio
  5. 清理項目並添加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>

默認情況下,我的Windows 10 64位僅啟用了Powershell 1.0版。 我更改了控制面板/程序/程序和功能/關閉Windows功能。

確保已啟用Windows Powershell 2.0引擎。

以非管理員模式重新啟動VS2015並正確安裝所有軟件包。

我和vs2013有同樣的問題,更改執行策略沒有解決它。 我發現唯一可行的解​​決方案是從VS卸載Nuget並再次安裝它。 步驟如下: https//stackoverflow.com/a/32619961/3853238

我需要做的就是重啟Visual Studio,打開NuGet Package Manager Console ,然后使用Manage NuGet Packages對話框。

關閉所有可視工作室實例,然后重試。 它對我有用:)

在嘗試了各種建議的修復之后,最終通過在Visual Studio中更新NuGet Package Manager擴展來解決它。

這在“工具” - >“擴展和更新”下完成,然后在“擴展和更新”對話框中更新 - > Visual Studio庫。 可能需要重新啟動Visual Studio。

如果您使用VS 2013 Update 5,則應手動為NuGet Packet Manager安裝更新2.8.7

錯誤報告有更多細節。

VS2015:更新了NuGet並且工作正常。

對我來說,訣竅是使用以下鏈接重新安裝NuGet Package Manager:

VS 2013: https//github.com/NuGet/Home/releases/download/2.8.7/NuGet.Tools.vsix

VS 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。 更新后所有問題都消失了。

如果以上答案適合你 -

  1. 打開運行 - Windows + R.
  2. 打開注冊表編輯器 - 鍵入regedit.exe
  3. 打開 - HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Policies \\ Microsoft \\ Windows \\ PowerShell
  4. 在右側窗格中 - 修改“ExecutionPolicy”並將其“Value Data”保留為空白。
  5. 重新啟動Visual Studio,現在您的Powershell可以正確初始化。

對我來說,將執行策略設置為Unrestricted不起作用。 我必須通過進入控制面板修復vs2013安裝。 修復安裝對我有用。

有同樣的問題,這解決了我(Powershell作為管理員):

Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value ByPass 

在嘗試了所有建議的解決方案后,VS 2015更新2沒有任何效果

從解決方案文件夾中刪除包文件夾並從visual studio恢復它對我有用

我遇到了類似的問題。 我通過在“打開或關閉Windows功能”中打開“Windows PowerShell 2.0”功能來修復它。 請注意,默認情況下此功能處於啟用狀態,我幾天前手動將其關閉。

我正在使用Windows 10 Pro 64位,同樣的問題是Visual Studio 2015和2017(32位和64位應用程序)

下載並安裝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更多權限后不知道它會搞亂視覺工作室2013和2015

此問題並不總是與PowerShell執行策略相關。 我的計算機配置為PowerShell x64和x86的“Unrestricted”,但我仍然在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; 本教程提供了更全面的說明 此外,如果您在使用PowerShell更改策略時遇到問題,那么作者會向您展示如何在Regedit中更改它。

黑暗中有很多刺傷,所以我會添加自己的刺。

在我的情況下,我還收到一條消息,說有一個丟失的鎖文件,並建議在包管理器控制台中運行dnu restore 我這樣做了,重新啟動了VS,現在一切正常。

對我有用的是:

  1. 將執行策略設置為Unrestricted。
  2. Find-Module ISEModuleBrowserAddon | Install-Module
  3. Import-Module ISEModuleBrowserAddon
  4. Find-Module ISEScriptAnalyzerAddOn | Install-Module
  5. Import-Module ISEScriptAnalyzerAddOn
  6. Import-Module ScriptBrowser
  7. 在ISE中,您需要Enable-ScriptBrowser

您的ISE中有模塊,腳本和分析器。

在Win 10 Pro,x64控制台主機5.0.10586.122中運行

祝好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM