【问题标题】:ASP.NET 5 roslyn dynamic compilationASP.NET 5 roslyn 动态编译
【发布时间】:2016-05-14 11:17:27
【问题描述】:

我有一个简单的ASP.NET 5 Web Api 应用程序,它是使用yo aspnet 制作的。我正在使用 Visual Studio Code(不想使用 Visual Studio)在 Windows 10 上工作。我想模拟非 Windows 环境下的开发。

据我所知roslyn 编译器应该动态编译更改的文件。但是当我使用以下命令运行我的应用程序dnu restore && dnx --watch web 应用程序启动。但如果我随后(dnx --watch web 仍在运行)更改一小部分代码并刷新网页,则注意已更改。

之前:

    // GET: api/values
    [HttpGet]
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

之后:

    // GET: api/values
    [HttpGet]
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2", "value3" };
    }

我检查了这是否是缓存的原因,但不是。我在这里错过了什么?

注意:

我注意到这可能是网络服务器的原因,我使用的是Kestrel。有一部分是我的project.json

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  }

【问题讨论】:

  • 只是为了确定:您是否真的保存了文件?
  • 好问题,是的,我做到了:)

标签: c# asp.net roslyn dnx kestrel-http-server


【解决方案1】:

我有这个问题的临时解决方案,使用gulp.js

// gulpfile.js
var gulp = require('gulp');
var bg = require("gulp-bg");

var dnxweb = null;
gulp.task('dnx:web:start', dnxweb = bg("dnx", "web"));
gulp.task('dnx:web:stop', () => {
    if (!dnxweb)
        return;
    dnxweb.setCallback((proc) => {
        if (proc.errorcode != 0)
            proc.exit(proc.errorcode);
    });
    dnxweb.stop();
});

gulp.task('watch', () => {
    gulp.watch('**/*.cs', ['dnx:web:stop', 'dnx:web:start']);
});

gulp.task('build', ['dnx:web:start', 'watch']);

【讨论】:

    猜你喜欢
    • 2011-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-06
    • 1970-01-01
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多