这是可能的。我刚刚使用 grunt-contrib-watch (https://github.com/gruntjs/grunt-contrib-watch) 在我的 ASP.NET 应用程序中进行了实时重新加载。只用了几分钟。
我以这篇文章为指导:
http://www.aliirz.com/javascript/2013/12/25/Live-Reload-with-Grunt/.
通过 ASP.NET 应用程序文件夹中的命令提示符执行此操作。
1。安装 grunt-contrib-watch
如果您还没有 package.json 文件并希望将依赖项保存在一个文件中:
npm init
然后将 Grunt 和 grunt-contrib-watch 添加到您的项目中:
npm install --save-dev grunt grunt-contrib-watch
2。配置 Grunt
接下来在同一个文件夹中创建一个Gruntfile.js。这是我的:
'use strict';
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.initConfig({
watch: {
views: {
files: [
'Views/**/*.cshtml',
'Scripts/**/*.js',
'Content/**/*.css',
'Content/images/**/*',
'bin/**/*.dll'
],
options: {
livereload: true,
}
}
}
});
}
3。运行实时重载服务器
在您的 ASP.NET 应用程序旁边运行您的实时重载服务器:
grunt watch
4。将代码段添加到 ASP.NET
最后,要在您的 ASP.NET 应用程序中启用它,只需将 live-reload sn-p 添加到您的布局和/或视图中:
<script src="http://localhost:35729/livereload.js"></script>