在 Visual Studio 中创建一个新的 TypeScript 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12684987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 00:46:23  来源:igfitidea点击:

Create a new TypeScript project in Visual Studio

visual-studiotypescript

提问by LordZardeck

How do I start writing TypeScript projects in Visual Studio? There's no option for it when I create a new project. I have Visual Studio 2012 installed along with the TypeScript add on

如何开始在 Visual Studio 中编写 TypeScript 项目?创建新项目时没有选择。我安装了 Visual Studio 2012 和 TypeScript 插件

采纳答案by nikeee

I just found the solution: Manual installation of the VS-Extension.

我刚刚找到了解决方案:手动安装 VS-Extension。

In some way, the VS-Extension is not getting installed. You can do it manually. There is a .vsixfile located in C:\Program Files (x86)\Microsoft SDKs\TypeScript\0.8.0.0called TypeScriptLanguageService.vsix. Try to run this file. It should install the TypeScript extension.

在某种程度上,没有安装 VS-Extension。您可以手动完成。有一个.vsix文件位于C:\Program Files (x86)\Microsoft SDKs\TypeScript\0.8.0.0名为TypeScriptLanguageService.vsix. 尝试运行此文件。它应该安装 TypeScript 扩展。

If you are running an x86-based system, try to look at C:\Program Files\Microsoft SDKs\TypeScript\0.8.0.0.

如果您运行的是基于 x86 的系统,请尝试查看C:\Program Files\Microsoft SDKs\TypeScript\0.8.0.0.

Worked for me. Now I can create TypeScript projects and it is listed in the Visual Studio extension list.

对我来说有效。现在我可以创建 TypeScript 项目,它列在 Visual Studio 扩展列表中。

Note that the newer versions of TypeScript dropped the folder 0.8.0.0. You may find the .vsixfile in C:\Program Files (x86)\Microsoft SDKs\TypeScript.

请注意,较新版本的 TypeScript 删除了文件夹0.8.0.0. 您可能会.vsixC:\Program Files (x86)\Microsoft SDKs\TypeScript.

回答by Fenton

You can add TypeScript files to an existing project using the Add > New Item dialog.

您可以使用 Add > New Item 对话框将 TypeScript 文件添加到现有项目。

enter image description here

在此处输入图片说明

You can also create a project of type HTML Application with TypeScript using the Add > New Project dialog. This project type is under Installed->(Templates)->Visual C#.

您还可以使用“添加”>“新建项目”对话框创建带有 TypeScript 的 HTML 应用程序类型的项目。此项目类型位于 Installed->(Templates)->Visual C# 下。

enter image description here

在此处输入图片说明

If these options are missing from Visual Studio, you should try re-installing the TypeScript Visual Studio plugin.

如果 Visual Studio 中缺少这些选项,您应该尝试重新安装TypeScript Visual Studio 插件

回答by Alexander Cosman

If you use Visual Studio 2017, the template 'HTML Application with TypeScript' has been removed from the templates.

如果您使用 Visual Studio 2017,模板“带有 TypeScript 的 HTML 应用程序”已从模板中删除。

But you can install the extension made by rich-newman on Github: https://github.com/rich-newman/typescript-html-application-vs2017-template

但是你可以在Github上安装rich-newman制作的扩展:https: //github.com/rich-newman/typescript-html-application-vs2017-template

To install it do the following:

要安装它,请执行以下操作:

  • Go to the 'Add New Project' window
  • At the left go to 'online' in the left tree view
  • Search for 'TypeScript HTML Application Template' enter image description here
  • Install the extension and the template should be available under 'installed --> TypeScript'
  • 转到“添加新项目”窗口
  • 在左侧转到左侧树视图中的“在线”
  • 搜索“TypeScript HTML 应用程序模板” 在此处输入图片说明
  • 安装扩展,模板应该在“已安装 --> TypeScript”下可用

回答by Neil

Followed the other answers but could not locate TypeScriptLanguageService.vsix after installing TypeScriptSetup.0.8.0.msi on Win7 64 w/ VS 2010.

遵循其他答案,但在 Win7 64 w/VS 2010 上安装 TypeScriptSetup.0.8.0.msi 后无法找到 TypeScriptLanguageService.vsix。

To install on VS 2010, use 7zipto open the above msi and extract "TypeScriptLS.vsix_File", remove the trailing _File, and run as usual.

要在 VS 2010 上安装,请使用7zip打开上述 msi 并提取“TypeScriptLS.vsix_File”,删除尾随的 _File,然后照常运行。

This gives a new TypeScript project template (but not a file template mysteriously), intellisense, code highlighting, etc.

这提供了一个新的 TypeScript 项目模板(但不是神秘的文件模板)、智能感知、代码突出显示等。

回答by Capaj

I didn't have the project and ts file templates also, tried reinstalling it(just by running vsix file) that didn't help, so I 1. uninstalled(from the VS2012 manager) the extension 2. closed VS2012 and then installed it again and voila- the Project and file template magically appeared. Thank god it worked- I can start playing with the language without having to run transcompilation manually every time.

我也没有项目和 ts 文件模板,尝试重新安装它(仅通过运行 vsix 文件)没有帮助,所以我 1. 卸载(从 VS2012 管理器)扩展 2. 关闭 VS2012 然后安装它再次,瞧——项目和文件模板神奇地出现了。谢天谢地,它奏效了——我可以开始玩这种语言,而不必每次都手动运行编译。

回答by Biranchi Panda

Installing typescript adds a new project type as well as adds a file type for existing projects. After installing typescript, you can try searching "typescript" in the new project window. It shows "HTML Application with TypeScript" to me.

安装 typescript 会添加新的项目类型并为现有项目添加文件类型。安装 typescript 后,您可以尝试在新项目窗口中搜索“typescript”。它向我显示了“带有 TypeScript 的 HTML 应用程序”。

Every .ts file typescript file will add a dependent .js file.

每个 .ts 文件 typescript 文件都会添加一个依赖的 .js 文件。

Hope this helps!

希望这可以帮助!

回答by EdSF

Old post, new suggestion:

旧帖子,新建议:

I've spent a few hours on this issue on Win8/VS2012. After multiple install/reinstall (of Typescript plugin v 0.8.3), the one thing that worked, was to run VS2012 in Administrator modeand (re)install Web Essentials 2012. That did the trick for me and I got Typescript as it's own section in Add New Project...(and all the other goodies mentioned above).

我在 Win8/VS2012 上花了几个小时来解决这个问题。在多次安装/重新安装(Typescript 插件 v 0.8.3)之后,有效的一件事是在管理员模式下运行 VS2012并(重新)安装Web Essentials 2012。这对我有用,我得到了 Typescript 作为它自己的部分Add New Project...(以及上面提到的所有其他好东西)。

What reminded me of the run in admin modewas the process to update documentation (if you want to install documentation locally) where it too had an annoying cryptic error. Running in admin mode was also the answer.

让我想起在管理模式下运行的是更新文档的过程(如果你想在本地安装文档),它也有一个令人讨厌的神秘错误。以管理员模式运行也是答案。

You don't have to run in admin mode all the time, just probably a good practice when updating the IDE itself (new plugins, etc.).

您不必一直以管理员模式运行,这可能是更新 IDE 本身(新插件等)时的一个好习惯。

回答by fra

For version 0.9.1.1 I was able to make it work following the instructions here: http://typescript.codeplex.com/wikipage?title=Compile-on-Save.

对于 0.9.1.1 版,我能够按照此处的说明使其工作:http://typescript.codeplex.com/wikipage?title=Compile-on-Save 。

Support for Typescript was just disabled on Web Essentials 2012 3.0: http://vswebessentials.com/changelog

刚刚在 Web Essentials 2012 3.0 上禁用了对 Typescript 的支持:http://vswebessentials.com/changelog

回答by Rob Lourens

Another tip - you need to install Visual Studio for Web. It will not work with just VS for Desktop. Also, you need to install the plugin after VS, so if you installed the plugin first, uninstall it then reinstall.

另一个提示 - 您需要安装 Visual Studio for Web。它不适用于桌面版 VS。另外,你需要在VS之后安装插件,所以如果你先安装了插件,先卸载再重新安装。