在wwwroot外部调试TypeScript文件 [英] Debugging TypeScript files outside wwwroot

查看:77
本文介绍了在wwwroot外部调试TypeScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何在ASP.NET 5中调试TypeScript文件? 假设解决方案的布局如下图所示.注意.ts脚本位于wwwroot文件夹之外,而编译的.js文件通过Grunt任务到达那里. 该任务还将创建一个引用原始.ts文件的.map文件.

How should I debug TypeScript files in ASP.NET 5? Suppose solution layout as on the following picture. Notice .ts Scripts are outside wwwroot folder and compiled .js file is getting there via Grunt task. The task also creates .map file which references the original .ts files.

但是请注意,引用不在wwwroot(../Scripts/app.ts)之外.显然,这在浏览器中不起作用.

Note however that reference goes outside wwwroot (../Scripts/app.ts). This obviously doesn't work in a browser.

有什么主意吗?

推荐答案

我向我的一个控制器添加了以下操作,其中appEnvironment是注入到您的控制器中的IApplicationEnvironment:

I added the following action to one of my controllers, where appEnvironment is an IApplicationEnvironment injected into your controller:

#if DEBUG

[ExcludeFromCodeCoverage]
[Route("Scripts/{*pathInfo}", Order = 500)]
public IActionResult TestTypescript(string pathInfo, System.Threading.CancellationToken cancellationToken)
{
    var path = appEnvironment.ApplicationBasePath + "/Scripts/" + pathInfo;
    if (System.IO.File.Exists(path) && pathInfo.EndsWith(".ts"))
    {
        return File(path, "application/javascript");
    }
    else
    {
        return HttpNotFound();
    }
}

#endif

为方便起见,新的Web服务器会删除../(出于安全性考虑,我假设),因此您甚至不必担心将它们放入路由"中. (请注意,您不需要在控制器本身上具有[RoutePrefix]属性,这些路径才能起作用.)

Conveniently, the new web servers strip out the ../ (I'm assuming for security purposes), so you don't even have to worry about having them in the Route. (Note that you need to not have a [RoutePrefix] attribute on the controller itself for these paths to work.)

这篇关于在wwwroot外部调试TypeScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆