在现有的 Visual Studio 网站项目中使用 TypeScript [英] Using TypeScript in an existing Visual Studio Web Site project

查看:31
本文介绍了在现有的 Visual Studio 网站项目中使用 TypeScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已设置为网站"项目的现有 Visual Studio 项目.您可以通过转到 File->New Web Site 来创建这样的项目.这是与Web 应用程序项目"不同的项目类型.

I've got an existing Visual Studio project that was setup as a "Web Site" project. You can create projects like this by going to File->New Web Site. This is a different project type than a "Web Application Project".

我想在这个项目中加入一些 TypeScript.但是,我不知道如何指示 Visual Studio构建"我的 .ts 文件并生成 .js 文件.我有 VS2012 TypeScript 插件,我可以创建一个 TypeScript 项目,如 此处概述.该项目运行良好,但这更像是Web 应用程序项目".这是与网站项目"不同的项目类型.

I'd like to mix in some TypeScript on this project. However, I can't figure out how to instruct Visual Studio to "build" my .ts files and generate .js files. I've got the VS2012 TypeScript plugin, and I'm able to a create a TypeScript project, as outlined here. That project works fine, but that's more along the lines of a "Web Application Project". It's a different project type than a "Web Site Project".

此外,当我创建 .ts 文件时,编辑器在该文件中为我提供了 TypeScript 语法突出显示和智能感知.但同样,我不知道如何让它将 TypeScript 编译为 JavaScript.

Also, when I create .ts file, inside that file the editor gives me TypeScript syntax highlighting and intellisense. But again, I can't figure out how to get it to compile the TypeScript to JavaScript.

有点帮助?​​

推荐答案

Visual Studio 现在支持 TypeScript 文件的保存时编译".我正在使用 Visual Studio 2013 更新 2,并且我可以通过转到工具 -> 选项 -> 文本编辑器 -> TypeScript -> 项目,并选中自动编译不属于项目的 TypeScript 文件"框,在网站项目中打开此功能.我不知道为什么它被标记为这样,因为它显然正在编译文件,这些文件是我项目的一部分...

Visual Studio now supports "compile on save" for TypeScript files. I'm using Visual Studio 2013 Update 2, and I can turn this on in a Web Site project by going to Tools -> Options -> Text Editor -> TypeScript -> Project, and checking the box "Automatically compile TypeScript files which are not part of a project." I don't know why it's labeled like this, because it is clearly compiling files which are part of my project...

对此的许多其他答案不适用于网站项目,因为您无法连接到构建过程.对于网站项目,没有 csproj 或 vbproj 文件,如构建由 IIS 处理,而不是 Visual Studio.

Many of the other answers to this are not applicable to Web Site Projects, because you can't hook into the build process. With a Web Site Project, there is no csproj or vbproj file, as the build is handled by IIS, not Visual Studio.

如果您使用的是网站项目,并且保存时编译"对您不起作用,那么只有几种选择:

If you're using a Web Site Project, and "compile on save" doesn't work for you, there are only a few alternatives:

1) 使用命令行 TSC 编译器手动编译您的代码.

1) Use the command line TSC compiler to manually compile your code.

2) 创建用于手动编译文件的自定义工具.您可以配置它以在 Visual Studio 中使用.

2) Create a custom tool for manually compiling your files. You can configure this for use in Visual Studio.

3) 创建一个按需编译".aspx 页面,该页面将编译 TypeScript 并将其作为 JavaScript 返回.

3) Create an "on-demand compilation" .aspx page that will compile the TypeScript and return it as JavaScript.

4) 使用 TypeScript Compile JavaScript 项目在浏览器中自动执行您的代码.这为您提供了通常随网站项目一起提供的按需编译".

4) Use the TypeScript Compile JavaScript project to automatically your code in the browser. This gives you the "on-demand compilation" that normally comes with Web Site Projects.

在保存时编译"在 VS 中工作之前,我使用的是 TypeScript 编译.现在我很高兴使用保存时编译".

Before "compile on save" was working in VS, I was using the TypeScript Compile. Now I'm happily using "compile on save."

这篇关于在现有的 Visual Studio 网站项目中使用 TypeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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