在构建时编译TypeScript [英] Compile TypeScript on build

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

问题描述

我有一个包含一些TypeScript文件的ASP.NET Core项目(一个.xproj文件).当我构建该项目时,所有.ts文件都将自动转换为.js文件.另外,如果我修改然后保存.ts文件,则会生成其.js(compileOnSave).很好.

I have a ASP.NET Core project (a .xproj file) containing some TypeScript files. When I build this project, all .ts files are automatically transpiled to .js files. Also if I modify and then save a .ts file its .js is generated (compileOnSave). This is nice.

在同一解决方案中,我有一个.NET Core类库(也是一个.xproj文件).该项目还包含一个tsconfig.json文件和一些TypeScript文件. compileOnSave功能很好用,但是当我构建项目时,.ts文件没有被编译.这意味着我需要手动修改和保存.ts文件以生成.js文件.

In the same solution I have a .NET Core Class Library (also a .xproj file). This project also contains a tsconfig.json file and some TypeScript files. The compileOnSave feature works nice, but when I build the project, the .ts files are not compiled. This means that I need to modify and save the .ts file manually to generate the .js file.

如何配置我的类库项目,以便在构建项目时创建.js文件?

How do I have to configure my class library project so that .js files are created when I build the project?

我正在使用Visual Studio 2015 Update 3,并且安装了"TypeScript for Microsoft Visual Studio" 2.0.6.0版扩展名.

I'm working with Visual Studio 2015 Update 3 with the "TypeScript for Microsoft Visual Studio" version 2.0.6.0 extension installed.

推荐答案

添加 <Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" /> 到xproj文件以获取内置到JS的打字稿(从我的ASP.NET Core-.xproj文件中获得了这一行)

Add <Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" /> to the xproj file to get typescript built to JS (got the line from my ASP.NET Core - .xproj file)

这篇关于在构建时编译TypeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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