How do you rerun dnx. Kestrel command on any file changes?
I found the following work using nodemon from
https://github.com/johnpapa/aspnet5-starter-demo#dnxmon
nodemon --ext "cs,json" --exec "dnx . kestrel"
source to share
You can use the dnx-watch command for this. It did not exist when the original question was asked, but was added in beta 8 in September 2015. You install it with
dnu commands install Microsoft.Dnx.Watcher
Start it by simply giving it the command you would give dnx. So, replace
dnx web
from
dnx-watch web
You can read more here: http://ardalis.com/get-started-with-dnx-watch
source to share
This is by design. Today there is no out-of-the-box solution for automatically restarting the server after it stops due to the file watcher.
Visual Studio has special code that monitors the process and restarts it.
However, we are tracking this issue and we plan to address it in a future iteration.
source to share
Although the selected solution is shorter, here is what I am doing in an angular application that is managed from grunt
The application has an interface and a server-side api.
First there is a task shell
to start the api:
shell: {
api:{
options: {
execOptions : {
cwd: '..\\$working_directory'
},
callback : function (err, stdout, stderr, cb) {
restartServer('shell:api',err,cb);
}
},
command: function() {
return 'dnx --watch localfarm';
}
},
at the top of mine gruntfile
I define a function that restarts the server:
var restartServer = function (task, err, cb) {
var timeoutInSec = 30;
if (err === null)
timeoutInSec = 2;
grunt.log.write(task + ' Task ended. Retrying in ' + timeoutInSec + ' seconds');
setTimeout(function() {
grunt.log.write('retrying ' + task );
grunt.task.run(task);
cb();
}, timeoutInSec*1000); };
Every time something changes in the code, the process dnx --watch
is killed automatically. grunt
then waits 2 seconds and restarts the process dnx
. If it dnx
doesn't work, it waits 30 seconds until it tries again. This gives me time to fix the code. (In my version of the code, I also use the beep
api to get notification on reload.)
To start the farm (frontend and backend), I added a parallel task that starts multiple threads:
concurrent: {
...
farm: {
tasks: ['shell:api', 'serve'],
options: { logConcurrentOutput: true, limit: 10 }
}
...
}
source to share
this command works better on windows (if you have kestrel command installed):
nodemon --ext "cs, json" --exec "dnx --watch kestrel"
> Blockquote
C:\Users\name\YoWebApp>**nodemon --ext "cs,json" --exec "dnx . kestrel"**
6 Oct 14:46:13 - [nodemon] 1.7.1
6 Oct 14:46:13 - [nodemon] to restart at any time, enter `rs`
6 Oct 14:46:13 - [nodemon] watching: *.*
6 Oct 14:46:13 - [nodemon] starting `dnx . kestrel`
System.InvalidOperationException: Unable to load application or execute command '.'. Available commands: kestrel, web, ef, mon.
at Microsoft.Dnx.ApplicationHost.Program.ThrowEntryPointNotfoundException(DefaultHost host, String applicationName, Exception innerException)
at Microsoft.Dnx.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args)
at Microsoft.Dnx.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at Microsoft.Dnx.Host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env, FrameworkName targetFramework)
at Microsoft.Dnx.Host.RuntimeBootstrapper.ExecuteAsync(String[] args, FrameworkName targetFramework)
at Microsoft.Dnx.Host.RuntimeBootstrapper.Execute(String[] args, FrameworkName targetFramework)
6 Oct 14:46:14 - [nodemon] app crashed - waiting for file changes before starting...
6 Oct 14:46:44 - [nodemon] restarting due to changes...
6 Oct 14:46:44 - [nodemon] starting `dnx . kestrel`
System.InvalidOperationException: Unable to load application or execute command '.'. Available commands: kestrel, web, ef, mon.
at Microsoft.Dnx.ApplicationHost.Program.ThrowEntryPointNotfoundException(DefaultHost host, String applicationName, Exception innerException)
at Microsoft.Dnx.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args)
at Microsoft.Dnx.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at Microsoft.Dnx.Host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env, FrameworkName targetFramework)
at Microsoft.Dnx.Host.RuntimeBootstrapper.ExecuteAsync(String[] args, FrameworkName targetFramework)
at Microsoft.Dnx.Host.RuntimeBootstrapper.Execute(String[] args, FrameworkName targetFramework)
source to share