How should I reference HttpClient using a project.json file?
I want both frameworks to work: dnx451 and dnxcore50.
Here is my current attempt at the project.json file. (I've removed the irrelevant parts.)
{
"dependencies": {
"Microsoft.Net.Http": "2.2.29",
"Microsoft.Net.Http.Headers": "1.0.0-beta4",
"System.Net.Http": "4.0.0-beta-22816"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Net.Http": "4.0.0.0"
}
},
"dnxcore50": { }
}
}
Discovering the dependencies I do have listed was a trial-and-error procedure.
With this project.json file, the dnxcore50 context properly resolves all the classes in this example block of code, but it fails to resolve HttpRequestMessage, HttpMethod, and MediaTypeWithQualityHeaderValue with the dnx451 context:
var request = new HttpRequestMessage(HttpMethod.Get, "...");
request.Headers.Accept.Clear();
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/..."));
var response = await client.SendAsync(request);
var model = await response.EnsureSuccessStatusCode().Content.ReadAsAsync<SomeModel>();
As of the time of posting (June 11, 2015) this is the combination that worked for me for both
dnx451anddnxcore50.