{"id":9133,"date":"2016-09-05T03:16:19","date_gmt":"2016-09-04T19:16:19","guid":{"rendered":"http:\/\/bohu.net\/blog\/?p=9133"},"modified":"2016-09-05T03:16:19","modified_gmt":"2016-09-04T19:16:19","slug":"%e8%a7%a3%e5%86%b3nuget%e7%a8%8b%e5%ba%8f%e5%8c%85%e6%9b%b4%e6%96%b0%e5%ae%89%e8%a3%85%e5%a4%b1%e8%b4%a5%e7%9a%84%e9%94%99%e8%af%af","status":"publish","type":"post","link":"https:\/\/www.bohu.net\/blog\/9133\/","title":{"rendered":"\u89e3\u51b3NuGet\u7a0b\u5e8f\u5305\u66f4\u65b0\u5b89\u88c5\u5931\u8d25\u7684\u9519\u8bef"},"content":{"rendered":"<p>\u5728 <strong>\u7ba1\u7406NuGet\u7a0b\u5e8f\u5305<\/strong> \u4e2d\u66f4\u65b0\u7a0b\u5e8f\u5305\uff0c\u51fa\u73b0\uff1a<\/p>\n<pre class=\"lang-bsh prettyprint prettyprinted\"><code><span class=\"typ\">Failed<\/span><span class=\"pln\"> to initialize the <\/span><span class=\"typ\">PowerShell<\/span><span class=\"pln\"> host<\/span><span class=\"pun\">.<\/span> <span class=\"typ\">If<\/span><span class=\"pln\"> your <\/span><span class=\"typ\">PowerShell<\/span><span class=\"pln\"> execution policy setting is <\/span><span class=\"kwd\">set<\/span><span class=\"pln\"> to <\/span><span class=\"typ\">AllSigned<\/span><span class=\"pun\">,<\/span><span class=\"pln\"> open the <\/span><span class=\"typ\">Package<\/span> <span class=\"typ\">Manager<\/span> <span class=\"typ\">Console<\/span><span class=\"pln\"> to initialize the host first<\/span><\/code><\/pre>\n<p><strong>1. Step<\/strong><\/p>\n<p>Open <code>Windows PowerShell<\/code>, run as <code>Administrator<\/code><\/p>\n<p><strong>2. Step<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td class=\"votecell\"><\/td>\n<td class=\"answercell\">\n<div class=\"post-text\">\n<p>Setting an execution policy to RemoteSigned or Unrestricted should work. It must be changed under an administrator mode via a PowerShell console. Be aware that changes will be applied according to the bit version of the PowerShell console, so 32bit or 64 bit. So if you want to install a package in Visual Studio (32 bit version) which requires a specific policy you should change settings of the policy via PowerShell (x86).<\/p>\n<p>The command in PowerShell (as administrator) to set the policy to unrestricted (as noted by @Gabriel in the comments) is:<\/p>\n<pre class=\"lang-bsh prettyprint prettyprinted\"><code><span class=\"pln\">start<\/span><span class=\"pun\">-<\/span><span class=\"pln\">job <\/span><span class=\"pun\">{<\/span> <span class=\"typ\">Set<\/span><span class=\"pun\">-<\/span><span class=\"typ\">ExecutionPolicy<\/span> <span class=\"typ\">Unrestricted<\/span> <span class=\"pun\">}<\/span> <span class=\"pun\">-<\/span><span class=\"typ\">RunAs32<\/span> <span class=\"pun\">|<\/span><span class=\"pln\"> wait<\/span><span class=\"pun\">-<\/span><span class=\"pln\">job <\/span><span class=\"pun\">|<\/span> <span class=\"typ\">Receive<\/span><span class=\"pun\">-<\/span><span class=\"typ\">Job<\/span><\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><em><strong>OR<\/strong><\/em><\/p>\n<p>NuGet is using the 32 bit console, so it wont be affected by changes to the 64 bit console. Run the following script to make sure you are configuring the 32 bit console.<\/p>\n<pre class=\"lang-bsh prettyprint prettyprinted\"><code><span class=\"pln\">start<\/span><span class=\"pun\">-<\/span><span class=\"pln\">job <\/span><span class=\"pun\">{<\/span> <span class=\"typ\">Set<\/span><span class=\"pun\">-<\/span><span class=\"typ\">ExecutionPolicy<\/span> <span class=\"typ\">RemoteSigned<\/span> <span class=\"pun\">}<\/span> <span class=\"pun\">-<\/span><span class=\"typ\">RunAs32<\/span> <span class=\"pun\">|<\/span><span class=\"pln\"> wait<\/span><span class=\"pun\">-<\/span><span class=\"pln\">job <\/span><span class=\"pun\">|<\/span> <span class=\"typ\">Receive<\/span><span class=\"pun\">-<\/span><span class=\"typ\">Job<\/span><\/code><\/pre>\n<p><strong>3. Step<\/strong><\/p>\n<p>Restart <code>Visual Studio<\/code><\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>\u5982\u679c<span class=\"goog-text-highlight\">\u6240\u6709\u7684\u653f\u7b56\u662f\u6b63\u786e\u7684\uff0c\u4f46\u5b89\u88c5\u5305\u65f6\uff0c\u4ecd\u6709\u9519\u8bef<\/span><\/p>\n<blockquote><p>\u65e0\u6cd5\u521d\u59cb\u5316PowerShell\u4e3b\u673a\u3002\u5982\u679c\u4f60\u7684PowerShell\u6267\u884c\u7b56\u7565\u8bbe\u7f6e\u4e3a\u4f7f\u7528AllSigned\uff0c\u6253\u5f00\u5305\u7ba1\u7406\u5668\u63a7\u5236\u53f0\u9996\u5148\u521d\u59cb\u5316\u4e3b\u673a\u3002<\/p><\/blockquote>\n<p>\u8be5<strong>\u89e3\u51b3\u65b9\u6848<\/strong>\uff1a <strong>\u5378\u8f7d<\/strong> <strong>\u00a0NuGet\u5305\u7ba1\u7406\u5668\u00a0<\/strong>\u63d2\u4ef6\uff0c\u5e76<strong>\u91cd\u65b0\u5b89\u88c5<\/strong>\u5b83\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 \u7ba1\u7406NuGet\u7a0b\u5e8f\u5305 \u4e2d\u66f4\u65b0\u7a0b\u5e8f\u5305\uff0c\u51fa\u73b0\uff1a Failed to initialize the PowerS &hellip; <a href=\"https:\/\/www.bohu.net\/blog\/9133\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u89e3\u51b3NuGet\u7a0b\u5e8f\u5305\u66f4\u65b0\u5b89\u88c5\u5931\u8d25\u7684\u9519\u8bef\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4,12,26,27],"tags":[270,300,402],"class_list":["post-9133","post","type-post","status-publish","format-standard","hentry","category-net","category-c-net","category-windows","category-26","category-27","tag-nuget","tag-powershell","tag-visual-studio"],"_links":{"self":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/9133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/comments?post=9133"}],"version-history":[{"count":0,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/9133\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/media?parent=9133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/categories?post=9133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/tags?post=9133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}