I'm looking for a way to hit a web app/restful service URL from msbuild script to trigger remote procedure. Is there any way how I can do that except calling that external app? Ideally I'm looking for a way to break a build sequence if service returned something else that http 200
I use the MSBuild Community Tasks a lot. They add extra tasks for MSBuilds. In there is a HttpRequest task which, from the look of it, does what you want.
<HttpRequest Url="http://<mydomain.com>/index.php?checkdb=1"
EnsureResponseContains="Database upgrade check completed successfully."
FailOnNon2xxResponse="true" />
Hope this helps
-
1Thanks this one works, I have updated MSbuild Community URL since they have moved to Github. – Major May 13 '19 at 9:31
In version 4 of the MSBuild Community Tasks, the HttpRequest
task was replaced by HttpWebRequest with a different syntax:
<MSBuild.ExtensionPack.Web.HttpWebRequest
TaskAction="GetResponse" Url="http://www.freetodev.com">
<Output TaskParameter="Response" ItemName="ResponseDetail"/>
<Output TaskParameter="Status" PropertyName="ResponseStatus"/>
</MSBuild.ExtensionPack.Web.HttpWebRequest>
-
1Both answers are good, but I like this one better since I need to use the actual Response message and just show Warning if something goes wrong and check the next sites, etc. Meanwhile other task trows error. Which is not good in my case. Thanks for the answer. – Major May 13 '19 at 9:43
-