你怎么重运行的dnx。任何文件更改的红隼命令?
How do you re-run the dnx . kestrel command on any file changes?
我如何执行我的 kestrel 服务器以在任何文件更改时重新启动?而不是停下来?
我试过了
dnx --watch . kestrel
但是服务器刚刚停止,我必须手动重新运行命令
我也尝试过使用 npm watch 命令,但这似乎只是自己绊倒了
watch 'dnx --watch . kestrel' .
这是设计使然。今天没有开箱即用的解决方案可以在服务器因文件观察器而停止后自动重新启动服务器。
Visual Studio 有一些特殊的代码可以监视进程并重新启动它。
但是,我们 an issue 正在跟踪这个问题,我们计划在未来的迭代中解决它。
我发现以下解决方法是使用
中的 nodemon
https://github.com/johnpapa/aspnet5-starter-demo#dnxmon
nodemon --ext "cs,json" --exec "dnx . kestrel"
虽然选择的解决方案更短,但这是我在 angular 应用程序中所做的,该应用程序由 grunt
驱动
该应用程序有一个前端和一个 api 后端。
首先有一个 shell
任务用于启动 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';
}
},
在我的 gruntfile
顶部,我定义了重新启动服务器的函数:
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); };
每次代码发生变化时,dnx --watch
进程都会自动终止。 Grunt
然后等待 2 秒并重新启动 dnx
进程。如果 dnx
失败,它将等待 30 秒直到再次尝试。这让我有时间修复代码。
(在我的代码版本中,我还使用 beep
在 api 重新加载时获得通知。)
我向 运行 农场(前端和后端)添加了一个启动多线程的并发任务:
concurrent: {
...
farm: {
tasks: ['shell:api', 'serve'],
options: { logConcurrentOutput: true, limit: 10 }
}
...
}
此命令在 windows 上运行得更好(如果您定义了 kestrel 命令):
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)
您可以使用一个名为 dnx-watch 的命令。当最初的问题被问到时它不存在,但在 2015 年 9 月的 beta 8 中被添加。你使用
安装它
dnu commands install Microsoft.Dnx.Watcher
您 运行 它只需将您本应传递给 dnx 的命令传递给它即可。所以,替换
dnx web
和
dnx-watch web
您可以在此处了解更多信息:http://ardalis.com/get-started-with-dnx-watch
我如何执行我的 kestrel 服务器以在任何文件更改时重新启动?而不是停下来?
我试过了
dnx --watch . kestrel
但是服务器刚刚停止,我必须手动重新运行命令
我也尝试过使用 npm watch 命令,但这似乎只是自己绊倒了
watch 'dnx --watch . kestrel' .
这是设计使然。今天没有开箱即用的解决方案可以在服务器因文件观察器而停止后自动重新启动服务器。
Visual Studio 有一些特殊的代码可以监视进程并重新启动它。
但是,我们 an issue 正在跟踪这个问题,我们计划在未来的迭代中解决它。
我发现以下解决方法是使用
中的 nodemonhttps://github.com/johnpapa/aspnet5-starter-demo#dnxmon
nodemon --ext "cs,json" --exec "dnx . kestrel"
虽然选择的解决方案更短,但这是我在 angular 应用程序中所做的,该应用程序由 grunt
该应用程序有一个前端和一个 api 后端。
首先有一个 shell
任务用于启动 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';
}
},
在我的 gruntfile
顶部,我定义了重新启动服务器的函数:
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); };
每次代码发生变化时,dnx --watch
进程都会自动终止。 Grunt
然后等待 2 秒并重新启动 dnx
进程。如果 dnx
失败,它将等待 30 秒直到再次尝试。这让我有时间修复代码。
(在我的代码版本中,我还使用 beep
在 api 重新加载时获得通知。)
我向 运行 农场(前端和后端)添加了一个启动多线程的并发任务:
concurrent: {
...
farm: {
tasks: ['shell:api', 'serve'],
options: { logConcurrentOutput: true, limit: 10 }
}
...
}
此命令在 windows 上运行得更好(如果您定义了 kestrel 命令):
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)
您可以使用一个名为 dnx-watch 的命令。当最初的问题被问到时它不存在,但在 2015 年 9 月的 beta 8 中被添加。你使用
安装它dnu commands install Microsoft.Dnx.Watcher
您 运行 它只需将您本应传递给 dnx 的命令传递给它即可。所以,替换
dnx web
和
dnx-watch web
您可以在此处了解更多信息:http://ardalis.com/get-started-with-dnx-watch