我到处寻找答案,但我想也许我的谷歌忍者技能缺乏.
我试图在Powershell中运行一个简单的命令,下载一个字符串(实际上,我想下载一个msi并运行它 - 但我已经将问题缩小到一个简单的例子).我正在运行的脚本是:
$client = New-Object System.Net.WebClient
$client.DownloadString("http://google.com") | Out-File google.html
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
Exception calling "DownloadString" with "1" argument(s): "Unable to connect to the remote server"
At line:1 char:1
+ $client.DownloadString("http://google.com") | Out-File google.html
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
Run Code Online (Sandbox Code Playgroud)
PSVersion = 4.0
我在同事的PC上运行了这个脚本(PSVersion = 3.0),它运行得很好.所以我知道代码有效.我还在C#控制台应用程序中重新创建了此代码,如下所示:
static void Main(string[] args)
{
using(var client = new System.Net.WebClient())
{
var content = client.DownloadString("http://google.com");
File.WriteAllText("D:\\google.html", content);
}
}
Run Code Online (Sandbox Code Playgroud)
这适用于我的机器 - 所以我知道这不是.NET Framework的问题.奇怪的是,我可以exe
从Powershell …
我遇到了依赖项降级错误的问题(事实证明,由于错误的 git 冲突解决方案,我在具有不同版本的 csproj 文件中对同一个包有两个引用 - 无论如何,不是问题)。
我试图发现这一点时尝试的一件事是从中删除包缓存%userprofile%\.nuget\packages
- 我删除了整个packages
文件夹。
然后我发现文件中有重复的包引用,csproj
并想“好吧,我将删除重复项并执行操作dotnet restore Blah.sln
,一切都会好起来的。不。我一直收到构建错误:
metadata file microsoft.codeanalysis.analyzers.dll could not be found
Run Code Online (Sandbox Code Playgroud)