问题
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?
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/33281884/publish-dnx-based-webjob-with-local-dependencies