Issue
Im trying to post a http request to "new relic" by using the "Publish" button in Visual Studio.
In my publishing profile I choose "web deploy" and then finnish my setup. After that I'll go in to my ".pubxml"-file and add a target at the bottom:
<Target Name="AfterBuild">
<Exec Command="curl -H "x-api-key:mykey"
-d "deployment[application_id]=appId"
-d "deployment[description]=MSbuild deploy using curl"
-d "deployment[revision]=0"
-d "deployment[changelog]=Deployed using MSBuild"
-d "deployment[user]=User"
-d http://api.newrelic.com/deployments.xml"/>
</Target>
</project>
In the error list in visual studio I get this:
Severity Code Description Project File Line Suppression State Error The command
"curl
-H "x-api-key:APPKEY"
-d "deployment[application_id]=APPID"
-d "deployment[description]=MSbuild deploy using curl"
-d "deployment[revision]=1"
-d "deployment[changelog]=Deployed using MSBuild"
-d "deployment[user]=User"
http://api.newrelic.com/deployments.xml"
exited with code 9009
If I run the curl command in curl.exe it works (the post succeeds) but not during msbuild.
As you can see above there are quotes around everything accept the url, (have tried that also)
I have tried specifying the path to curl like this
"C:\WINDOWS\system32\curl.exe"
but that doesent work eather.
I have removed the "ItemGroup" since I dont want the web config to be included (Have set the buildaction to "none" on the web config)
What can I try?
Updated
<Target Name="AfterBuild"> and <Message Text="Test"/>..
This runns successfully but I cant see the text "Test" in the build output.
<Target Name="AfterBuild">
<Exec WorkingDirectory="C:\Windows\System32\" Command="curl http://www.google.com"/>
This returns error 9009.
Proof that its in the correct directory:
Solution
When trying to reproduce your problem I tried a couple of things (running curl, running 64bit curl, running when it's in the PATH, running with specifying full path, running an executable from the system32 diretory), but the one thing I didn't try out of principle is copying curl to the system32 directory: doing that is almost never the correct solution for a problem, for a variety of reasons which can be found on the internet. And yes, today we found yet another reason why it's bad :]
MsBuild's Exec
task works by creating a temporary file including the Command
to run, and then launching cmd.exe /q /c <path/to/tempfile>
. The task does not just start cmd.exe though, but specifies the the full path by prepending it with Environment.GetFolderPath(Environment.SpecialFolder.System)
. Which returns C:\windows\SysWOW64
or similar when called from a 32bit process (i.e. msbuild) on a 64bit system.
As a result msbuild starts the 32bit cmd from C:\windows\SysWOW64\cmd.exe
. Being a 32bit process, the file system redirection gets invoked: if you tell a 32bit process to look in c:\windows\system32 it won't do that, but look in c:\windows\SysWOW64. And curl.exe is not there since you put it in system32. And so you get a code 9009.
Long story short: be a good Windows citizen and don't put curl.exe in sSystem32 or SysWOW64, and then either specify the full path to it when using Exec or add the directory where it is located to your PATH.
Answered By - stijn Answer Checked By - Robin (WPSolving Admin)