20

I'm trying to deploy a .NET Core Console App as an Azure WebJob. All files etc. are getting copied to the right directories but my console app its output is a .dll, so it requires dotnet.exe to start.

I've added a run.cmd file with the single command: dotnet QbiSync.dll. But the output is the following, it can't seem to find dotnet.exe:

[11/14/2016 13:15:29 > 4741da: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'
[11/14/2016 13:15:29 > 4741da: SYS INFO] Status changed to Running
[11/14/2016 13:15:29 > 4741da: INFO] 
[11/14/2016 13:15:29 > 4741da: INFO] D:\local\Temp\jobs\continuous\QbiSync\x4jkoxww.vy4>dotnet QbiSync.dll 
[11/14/2016 13:15:29 > 4741da: ERR ] 'dotnet' is not recognized as an internal or external command,
[11/14/2016 13:15:29 > 4741da: ERR ] operable program or batch file.
[11/14/2016 13:15:29 > 4741da: SYS ERR ] Job failed due to exit code 1
[11/14/2016 13:15:29 > 4741da: SYS INFO] Process went down, waiting for 60 seconds

Opening up a Console window using Kudu or in the Azure Portal and calling dotnet.exe both works fine. I've also tried hardlinks like:

  • "D:\Program Files (x86)\dotnet\dotnet.exe" QbiSync.dll
  • "\Program Files (x86)\dotnet\dotnet.exe" QbiSync.dll

But they also give errors like:

[11/14/2016 13:59:29 > 4741da: ERR ] The filename, directory name, or volume label syntax is incorrect.
[11/14/2016 13:59:29 > 4741da: INFO] D:\local\Temp\jobs\continuous\QbiSync\hzlkzj1q.0jt>"D:\Program Files (x86)\dotnet\dotnet.exe" QbiSync.dll 

Even though the dotnet.exe is actually located there.

Update:

Possibly related is that the source used @echo off at the start of the script. But this is also a "command" that doesn't seem to be accepted.

[11/14/2016 12:37:57 > 4741da: INFO] D:\local\Temp\jobs\continuous\QbiSync\3n44nly1.ucq>@echo off 
[11/14/2016 12:37:57 > 4741da: INFO] 
[11/14/2016 12:37:57 > 4741da: ERR ] '@echo' is not recognized as an internal or external command,

Sources used:

Raymen
  • 582
  • 6
  • 15
  • What happens if you try running your run.cmd manually from Kudu Console? – David Ebbo Nov 14 '16 at 15:00
  • 1
    As a quick test, I tried creating a continuous WebJob with a run.cmd that just has `dotnet.exe QbiSync.dll` (without having the dll). It failed with `The application to execute does not exist: 'D:\local\Temp\jobs\continuous\DotNetContJob\tgq45gw1.kb2\QbiSync.dll'`, which means it successfully launched dotnet.exe and only failed because the dll is not there. Can you try this same test to isolate? – David Ebbo Nov 14 '16 at 15:13
  • @DavidEbbo It successfully starts and has the expected output using the kudu console with `D:\local\Temp\jobs\continuous\QbiSync\jf0yv53s.i3c>run.cmd`. I'll check your second comment in a few minutes. – Raymen Nov 14 '16 at 15:17
  • @DavidEbbo Same error, dotnet.exe can't be found. Does it also use the WindowsScriptHost in your case? `SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'` – Raymen Nov 14 '16 at 15:30
  • 1
    `[11/14/2016 15:33:51 > e06c64: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost' [11/14/2016 15:33:51 > e06c64: SYS INFO] Status changed to Running [11/14/2016 15:33:51 > e06c64: INFO] [11/14/2016 15:33:51 > e06c64: INFO] D:\local\Temp\jobs\continuous\DotNetContJob\vocvjalz.qbl>dotnet.exe QbiSync.dll [11/14/2016 15:33:51 > e06c64: ERR ] The application to execute does not exist: 'D:\local\Temp\jobs\continuous\DotNetContJob\vocvjalz.qbl\QbiSync.dll'` – David Ebbo Nov 14 '16 at 15:34
  • @DavidEbbo Thanks, it seems there is more going on than just an issue with dotnet.exe. I've edited the post to tell that `@echo off` is also not being accepted. – Raymen Nov 14 '16 at 15:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/128076/discussion-between-david-ebbo-and-raymen). – David Ebbo Nov 14 '16 at 15:41

2 Answers2

26

The issue is that your run.cmd uses UTF-8 with BOM (byte order marks), which in some cases causes the script engine to misbehave. The fix is to not have the BOM.

There is a mention of this on the wiki (https://github.com/projectkudu/kudu/wiki/Web-Jobs), but granted it's easy to miss.

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • I am trying to run a web job from an HTTP Client. The file is a ZIP file . and contains a java class and bat file to run that java class. This runs okay when i do from POSTMAN. But when i use HTTP client, i get the following error always " '---i-NPsGbTVUpaP0CeJxMQVrHoDHvaxo3' is not recognized as an internal or external command" - Please help – Jagaran Aug 25 '17 at 09:35
  • @Jagaran if it only happen from some clients, it is likely unrelated. Please ask a new question – David Ebbo Aug 25 '17 at 14:28
  • No any HTTP Client i am using in java, it is the same. it works in CURL or loading from web console. My sample code below – Jagaran Aug 26 '17 at 09:27
  • No any HTTP Client i am using in java, it is the same. it works in CURL or loading from web console. My sample code below. I am using uni restHttpResponse jsonResponse = Unirest.put("https://azurewebjobtestbrms.scm.azurewebsites.net/api/triggeredwebjobs/TestJOb") .basicAuth("$AzureWebJobTestBRMS","XXX".header("Content-Disposition","attachement; filename=acvbgth.bat").header("Content-Type","zip").field("file", new ZipInputStream(new FileInputStream("AzureWebJob.zip")) ,ContentType.create("application/zip"),"AzureWebJob.zip").asBinary(); – Jagaran Aug 26 '17 at 09:32
  • Do you have any sample Java based HTTP Client where I can publish Azure Web Job? I have tried all Java REST clients. May be i am doing something wrong. The error I get in Azure console is '---i-NPsGbTVUpaP0CeJxMQVrHoDHvaxo3' is not recognized as an internal or external command, [08/25/2017 09:30:22 > e7f683: ERR ] operable program or batch file. – Jagaran Aug 26 '17 at 09:34
  • I feel Content type = applciation /zip is not happening correctly when using java. Please help us – Jagaran Aug 26 '17 at 09:35
  • This question has nothing to do with what you're describing. You need to start a new question. – David Ebbo Aug 26 '17 at 10:47
  • Done, please answer that sir – Jagaran Aug 26 '17 at 12:20
  • For me I managed to have the run.cmd run fine, only by adding `@echo off` at the beginning of the file, followed by a blank line. I the console, it fails on the echo but then it can execute dotnet xxxxx.dll – Loul G. Dec 11 '17 at 13:11
2

In my experience the simplest way to get a .NET Core Console App running within the context of an Azure WebJob is to create a self-contained .exe.

You can do this with the following command:

dotnet publish -r win10-x64 -c Release

Note that the above command produces a different output than a Right-click > Publish action.

This will create a folder called win10-x64 within the bin\Release\netcoreapp2.0 directory of your console app. Inside of the win10-x64 directory is another directory called publish.

Simply compress the ...bin\Release\netcoreapp2.0\win10-x64\publish folder and upload as a new WebJob.

The trigger mechanism will detect the .exe and run the code within the console app.

pim
  • 12,019
  • 6
  • 66
  • 69
  • You can also right click the project, click Publish, and create a Folder profile. Then publishing generates the exe and all the folders you mentioned. Zip up the publish folder and it's good to go as a web job. – Andrew Nov 24 '19 at 18:19