繁体   English   中英

如何在WP8中引用System.Net.Http?

[英]How to reference System.Net.Http in WP8?

我是WP8开发的新手,遇到了一个问题,即使经过数小时的搜索,我也无法解决。

我正在使用Visual Studio 2012,并已使用NuGet实现了System.Net.Http,已检查了引用,将local复制设置为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();
                });

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM