I'm trying to publish my DNX-based WebJob to Azure. To do this I add my project.json and Program.cs files to some ZIP-archive and upload it through Azure portal. This works fine, but now i want my WebJob project to reference some other local DNX-based project (just a simple class library). How do I upload it in this case?
2 Answers
Here is a sample repo that works https://github.com/ahmelsayed-test/DnxWebJobWithClassLibrary. Clone it, zip it, and upload it. It should work!
Unfortunately the support for DNX webJob isn't complete yet, so this scenario doesn't work out of the box, you need a magic run.cmd
that's in the repo and also below in this answer.
The folder structure for DNX is that projects should be in different sibling folders. So if you look at the folder structure in the repo it's like this
| run.cmd
|
+---ClassLibrary
| Class.cs
| project.json
|
\---ConsoleApp
Program.cs
project.json
in run.cmd
there is an environment variable DNX_CONSOLE_APP_PATH
that you need to point it to the project.json
of the console app manually. In this case it's ConsoleApp\project.json
once there is enough smarts in kudu You shouldn't need to have this run.cmd
in your webjob. If you look in kudu, it uses a very similar runDnxWebJob.cmd
It's just not smart enough to find the correct path for the console app yet.
@ECHO OFF
:: 1. Prepare environment
SET DNX_CONSOLE_APP_PATH=ConsoleApp\project.json
SET DNVM_CMD_PATH_FILE="%USERPROFILE%\.dnx\temp-set-envvars.cmd"
:: 2. Install DNX
IF EXIST global.json (
CALL PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';$CmdPathFile='%DNVM_CMD_PATH_FILE%';& '%SCM_DNVM_PS_PATH%' " install -File global.json
IF ERRORLEVEL 1 GOTO ERROR
) ELSE (
CALL PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';$CmdPathFile='%DNVM_CMD_PATH_FILE%';& '%SCM_DNVM_PS_PATH%' " install latest
IF ERRORLEVEL 1 GOTO ERROR
)
:: 3. Put DNX on the path
IF EXIST %DNVM_CMD_PATH_FILE% (
CALL %DNVM_CMD_PATH_FILE%
DEL %DNVM_CMD_PATH_FILE%
)
:: 4. Run dnu restore
CALL dnu restore
IF ERRORLEVEL 1 GOTO ERROR
:: 5. Run the WebJob
CALL dnx --project "%DNX_CONSOLE_APP_PATH%" run
IF ERRORLEVEL 1 GOTO ERROR
GOTO END
:ERROR
ENDLOCAL
ECHO An error has occurred during running DNX WebJob.
CALL :EXITSETERRORLEVEL
CALL :EXITFROMFUNCTION 2>NUL
:EXITSETERRORLEVEL
EXIT /b 1
:EXITFROMFUNCTION
()
:END
ECHO DNX WebJob ended
There is really nothing special about WebJobs here. The question to ask is: if you were to run this manually from some self-contained folder on your local machine, what set of files would you include? Then whatever this set of file is, you'll want to zip up for use in your WebJob.
-
So if I have say folder 'WebJob1" with project.json and Program.cs in it and folder 'ClassLib1' with project.json and Model.cs in it then I should zip just 2 those folders? I tried to do so, didn't work Commented Oct 22, 2015 at 14:12
-
Does it run locally if you have that exact same structure? If not, then the issue is more of a general dnx question but not specifically related to WebJobs. Commented Oct 22, 2015 at 19:09
-
I'm using the method described here: ahmelsayed.com/running-dnx-based-webjobs I'm not sure what "exact same structure" means in this case. Commented Oct 22, 2015 at 19:48
-