5

我对 WP8 开发相对较新,并且遇到了一个我无法弄清楚的问题,即使经过数小时的谷歌搜索。

我正在使用 Visual Studio 2012 并使用 NuGet 实现了 System.Net.Http,检查了引用,将本地复制设置为 true,但它不会构建。

这是迎接我的错误消息:

CA0001  Error Running Code Analysis CA0001 : The following error was encountered while reading module '3D Protect Premium': Could not resolve member reference: [System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]System.Net.Http.HttpClient::PostAsync.  [Errors and Warnings]   (Global)

我该如何解决这个问题,所以引用的版本是正确的?

编辑

下面添加的代码。这似乎没有问题,它只是引用 - 老实说,我认为这是我的误解,我只是不知道 System.Net.Http 程序集发生了什么!

//Creates a new HttpClient Instance
            var client = new HttpClient();

            // This is the postdata
            // Data forms an array and is used to populate the remote MySQL DB
            var postData = new List<KeyValuePair<string, string>>();
            postData.Add(new KeyValuePair<string, string>("name", "windowsphonetest"));
            postData.Add(new KeyValuePair<string, string>("latitude", LatitudeString));
            postData.Add(new KeyValuePair<string, string>("longitude ", LongitudeString));
            postData.Add(new KeyValuePair<string, string>("devID", "test"));


            HttpContent content = new FormUrlEncodedContent(postData);

            //The actual HTTP Transaction
            client.PostAsync("http://blah.com", content).ContinueWith(
                (postTask) =>
                {
                    postTask.Result.EnsureSuccessStatusCode();
                });
4

2 回答 2

3

System.Net.Http您尝试使用的软件包已被弃用,但您可以改用Microsoft.Net.Http

于 2013-06-30T19:15:33.407 回答
2

解决方案:删除所有依赖的 NuGet 包,清理解决方案,删除对 System.Net.* 程序集的引用。

按照 NuGet 的建议安装 Microsoft.Net.Http 及其依赖项。然后安装 Microsoft.Bcl.Async - 这是 NuGet 未标记的依赖项(感谢 keyboardP)

现在进入项目属性并禁用“构建时的代码分析” - 由于某种原因,此工具会超出版本号。现在代码构建和部署正常。

于 2013-06-30T20:57:20.393 回答