Closed HeribertAM closed 6 years ago
The HttpWebRequest
class exists in System.Net
only for the .NET Framework. In .NET Standard, it moved to a new package System.Net.Requests which is not part of "NETStandard.Library". The RoslynCodeTaskFactory
only supports APIs available in NETStandard.Library and you cannot specify NuGet packages to use at the moment.
That said, you can use the new HttpClient
class instead which is part of NETStandard.Library. You can see this comment for more information: https://github.com/dotnet/corefx/issues/7862#issuecomment-211986998
Here's a working sample that I coded up:
<UsingTask TaskName="GetProxy" TaskFactory="CodeTaskFactory" AssemblyFile="$(RoslynCodeTaskFactory)" Condition=" '$(RoslynCodeTaskFactory)' != '' ">
<Task>
<Reference Include="System.Net.http" />
<Reference Include="System.Text.RegularExpressions" />
<Reference Include="System.Threading.Tasks" />
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<Using Namespace="System.Net.Http"/>
<Using Namespace="System.Text.RegularExpressions"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
using(HttpClient client = new HttpClient())
{
HttpResponseMessage response = client.GetAsync("http://wpad/wpad.dat").Result;
response.EnsureSuccessStatusCode();
string content = response.Content.ReadAsStringAsync().Result;
Log.LogMessageFromText(content, MessageImportance.High);
}
]]>
</Code>
</Task>
</UsingTask>
Be sure to use the latest version (1.2.4) of the package, since I did have to fix a bug to make this work.
Many thanks!! Now it is working
I'm not sure if it is an issue or there is something wrong in my code, but the following task is not working:
When executing msbuild with target using this task the process gives an error: HttpWebRequest not found in spacename.
I would like to know if it should work or there is something wrong.
Thank you