作者:三号天宫 | 来源:互联网 | 2023-02-10 04:24
So I'm starting up a new .Net 4.0 project and will be doing some work with a public API. I'm planning on using the Microsoft HttpClient class so I installed the latest stable version of the Microsoft.Net.Http NuGet package (version 2.2.13). I'm looking at some POC code that a coworker put together, also using a NuGet package for HttpClient and notice that there's code like this:
因此,我将启动一个新的。net 4.0项目,并将使用公共API进行一些工作。我打算使用Microsoft HttpClient类,所以我安装了最新的稳定版Microsoft.Net。Http NuGet包(版本2.2.13)。我在看一个同事组装的POC代码,也使用NuGet包对HttpClient,并注意到有这样的代码:
HttpClient client = new HttpClient();
HttpResponseMessage respOnse= client.GetAync("/uri").Result;
DomainType result = response.Content.ReadAsAsync().Result;
In my project, after adding the reference to the Microsoft.Net.Http package, when I try to write similar code, I noticed that HttpResponseMessage doesn't have a ReadAsAsync()
method. After doing some digging in my coworker's POC solution, it looks like ReadAsAsync()
is actually an extension method in the System.Net.Http.Formatting
assembly. In this POC solution, there's a reference to System.Net.Http.Formatting, however it's pulling this file from the path C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Net.Http.Formatting.dll
.
在我的项目中,添加了对Microsoft.Net的引用。Http包,当我尝试编写类似的代码时,我注意到HttpResponseMessage没有ReadAsAsync
()方法。在我的同事的POC解决方案中进行了一些挖掘之后,看起来ReadAsAsync
()实际上是System.Net.Http中的扩展方法。格式组装。在这个POC解决方案中,有一个对System.Net.Http的引用。格式,但是把这个文件的路径C:\Program Files (x86)\Microsoft ASP.NET \ ASP。净MVC 4 \总成\ System.Net.Http.Formatting.dll。
My question is, is there a better solution to getting access to this extension method than referencing this assembly from my local ASP.Net installation? My concern is that this is going to cause a problem on our CI server since it's not likely to have ASP.Net installed. I guess I could copy System.Net.Http.Formatting to a Lib directory in my solution but I'm hoping there's a better option such as another NuGet package I'm missing that would give me this assembly.
我的问题是,是否有更好的方法来访问这个扩展方法,而不是从本地的ASP中引用这个程序集。网络安装?我的担心是,这会在我们的CI服务器上造成问题,因为它不太可能有ASP。网络安装。我想我可以复制System.Net.Http。在我的解决方案中格式化为Lib目录,但是我希望有一个更好的选项,比如我丢失的另一个NuGet包,它会给我这个程序集。
Thanks!
谢谢!
1 个解决方案