1

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 &quot;x-api-key:mykey&quot; 
 -d &quot;deployment[application_id]=appId&quot; 
 -d &quot;deployment[description]=MSbuild deploy using curl&quot; 
 -d &quot;deployment[revision]=0&quot; 
 -d &quot;deployment[changelog]=Deployed using MSBuild&quot; 
 -d &quot;deployment[user]=User&quot; 
 -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

&quot;C:\WINDOWS\system32\curl.exe&quot; 

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:

enter image description here

Hannes
  • 140
  • 1
  • 3
  • 18
  • *I get the 9009 error that comes from the curl.exe* are you sure? see http://stackoverflow.com/questions/1351830/what-does-exited-with-code-9009-mean-during-this-build – stijn Feb 08 '16 at 14:10
  • Hi I updated my question some more. Yes I have tried the path fixes. Well im not sure about the curl.exe. I can open cmd > enter "curl" and hit enter key > enter the code above. Then everything works. I guess that msbuild cant find curl thought its there at the physical path "C:\Windows\System32\curl.exe" – Hannes Feb 08 '16 at 18:33
  • What if you remove the newlines from the command? – stijn Feb 08 '16 at 20:15
  • If I just run and it get published but the message "test" isnt shown in the Build Output – Hannes Feb 09 '16 at 10:20
  • What does `` do? – stijn Feb 09 '16 at 14:27
  • It does nothing. bad example, but what I want to point out is that whatever i type inside the "Command" it seems to result with the same error. So I guess its something about the path but I cant really understand what it is. Anyway I tried another aproach and solved my problem using a classic post webrequest. But still I would love to know why this doesent work. – Hannes Feb 09 '16 at 16:40
  • *It does nothing* nothing as in *doesn't run* or as in *error* or as in *runs but shows no output* or ... ? Are you claiming even something as `` gives 9009? That would mean curl is not in that directory, or not accesible. Anyway, I can't reproduce any of your problems myself. (except the original command which gets 9009 because of the newlines) – stijn Feb 10 '16 at 09:15
  • I have edited my question again by adding a proof(the picture)of the local path to curl.exe I downloaded it from here: https://curl.haxx.se/latest.cgi?curl=win64-ssl-sspi If I just use "" then I get 9009. I alsway get 9009. – Hannes Feb 10 '16 at 10:20
  • Contrary to what you might think, it's not the correct directory... See answer. – stijn Feb 10 '16 at 12:59

2 Answers2

2

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.

stijn
  • 34,664
  • 13
  • 111
  • 163
1

curl is 64-bit if you call it like this works; %windir%\sysnative\curl

bertubezz
  • 361
  • 1
  • 8