ASP.Net 5 js,css 捆绑

ASP.Net 5 js, css bundling

我目前在任务中使用 gulp-bundle-assets 模块来将 css 和 js 捆绑到我的项目中。每次我 运行 它模块生成新的文件名确保浏览器将选择最新的包。但是,每当文件名更改时,我都需要在 html 中手动更改文件引用。 gulp-bundle-asset 提出了一种通过读取 json 文件以编程方式更新视图的方法。

在 Visual Studio 中处理动态文件名捆绑的正确方法是什么?

如何处理图片、字体等静态内容的相对路径?

谢谢!

我是 gulp-bundle-assets. I actually created an example of this awhile back using ASP.NET 5 (now named ASP.NET Core v1) seen here: https://github.com/dowjones/gulp-bundle-assets-example-aspnet-5. You'll want to rely on the bundle.result.json 文件的作者。

关键片段如下:

// read bundle.result.json
public async Task<dynamic> GetBundleResult()
{
    string fileName = Path.Combine(_appEnvironment.ApplicationBasePath, "bundle.result.json");
    string jsonText = File.ReadAllText(fileName);
    return await Task.FromResult(JObject.Parse(jsonText));
}

在您看来:

@inject ExampleMVC6Application.Services.BundlerService Bundler
@{
    dynamic Bundles = await Bundler.GetBundleResult();
}
<!DOCTYPE html>
<html>
    <head>
        @Html.Raw((object)Bundles.vendor.styles)
        @Html.Raw((object)Bundles.main.styles)
    </head>
    ...