win 10 更新后,vs中的nuget无法使用

参考:

https://stackoverflow.com/questions/23353951/cant-install-nuget-package-because-of-failed-to-initialize-the-powershell-host

https://stackoverflow.com/a/32940627/3218732

I had the same problem after upgrading to Windows 10.

This worked for me

Close Visual Studio
Run Powershell as admin
Run Set-ExecutionPolicy Unrestricted
Run Visual studio as admin
Clean the project and add the nuget package
If it still doesn't work try editing 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

Visual Studio 2017: C:\Users\<UserName>\AppData\Local\Microsoft\VisualStudio\15.0_ab60ca3c

Add the following


<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>


在vs对应的目录中,找到devenv.exe.config文件,找到 assemblyBinding 节点,把上面的配置放到该节点的最后面,如图所示:

win 10 更新后,vs中的nuget无法使用