typescript 打字稿编译时使用 Visual Studio 2013 保存?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17711542/
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 01:06:58  来源:igfitidea点击:

Typescript compile on save with Visual Studio 2013?

typescriptvisual-studio-2013

提问by Ken Smith

I can't get Compile-on-Save to work with VS2013. I installed VS2013, reinstalled TS 0.9.0.1, and under "Tools", "Options", Typescript/Project/General, I've checked both of the "Compile on save" options. But when I add a new TS file to my project, and then edit it and save it, the changes aren't reflected in the associated .js file.

我无法让 Compile-on-Save 与 VS2013 一起使用。我安装了 VS2013,重新安装了 TS 0.9.0.1,在“工具”、“选项”、Typescript/项目/常规下,我检查了两个“保存时编译”选项。但是当我向我的项目添加一个新的 TS 文件,然后编辑它并保存它时,更改不会反映在关联的 .js 文件中。

Am I doing something wrong? Is anybody else having this problem?

难道我做错了什么?还有其他人有这个问题吗?

回答by Daniel

Thissolved the problem for me:

为我解决了问题:

  1. Go to Options under the Tools menu.
  2. Expand options for Text Editor
  3. Expand options for TypeScript
  4. Expand options for Project
  5. Check “Automatically compile TypeScript file which are not part of the project”
  1. 转到工具菜单下的选项。
  2. 展开文本编辑器的选项
  3. 扩展 TypeScript 的选项
  4. 扩展项目选项
  5. 勾选“自动编译不属于项目的 TypeScript 文件”

回答by rekna

I had the following situation: the project was created using vs2012 and an earlier version of typescript. I upgraded to VS2013 and the latest version of typescript (0.9.1.1) and scripts were not compiled on save.

我有以下情况:该项目是使用 vs2012 和早期版本的打字稿创建的。我升级到 VS2013 并且最新版本的 typescript (0.9.1.1) 和脚本没有在保存时编译。

I then excluded the typescript file from my project and added it again using Add existing file. After that the typescript file compiles fine on save!!

然后我从我的项目中排除了打字稿文件,并使用添加现有文件再次添加了它。之后打字稿文件在保存时编译正常!!

回答by cirrus

TypeScript 0.9.5 compile on save stopped working for me on an existing project after I upgraded to Web Essentials 1.85 (Feb 14). I reinstalled both to no avail but after seeing it work for new projects I tried changing this line in my csproj, from this;

在我升级到 Web Essentials 1.85(2 月 14 日)后,TypeScript 0.9.5 compile on save 在现有项目上停止工作。我重新安装了两者都无济于事,但在看到它适用于新项目后,我尝试在我的 csproj 中更改此行,从这里开始;

<Project ToolsVersion="4.0" />

to

<Project ToolsVersion="12.0"/>

And magically, compile on save started working again.

神奇的是,保存时编译再次开始工作。

回答by Brett Postin

Try following these instructions:

尝试按照以下说明操作:

Compile-on-Save

保存时编译

I've been struggling to get my head around this too but I think I have it sorted. I think part of the confusion comes from the differences in approach between WebEssentials and the new TypeScript plugin integration.

我也一直在努力解决这个问题,但我想我已经解决了。我认为部分混淆来自 WebEssentials 和新的 TypeScript 插件集成之间的方法差异。

I was an early adopter of TypeScript and used the WebEssentials tooling in 2012 to compile on save. I had this configured to generate .js and .min.js files, which were both added to the project automatically.

我是 TypeScript 的早期采用者,并在 2012 年使用 WebEssentials 工具在保存时进行编译。我将其配置为生成 .js 和 .min.js 文件,这两个文件都会自动添加到项目中。

When upgrading to VS 2013 I was looking for the same functionality from the in-built TypeScript support, however it does not exist (as far as I can tell).

升级到 VS 2013 时,我正在从内置的 TypeScript 支持中寻找相同的功能,但它不存在(据我所知)。

Instead I believe the integrated tooling in 2013 covers both development and production workflows.

相反,我相信 2013 年的集成工具涵盖了开发和生产工作流程。

The above instructions set you up for build time compilation which should occur during release. During development the "Compile on Save" feature generates the files on disk, but does not add them to the project.

上述说明为您设置了应该在发布期间进行的构建时编译。在开发过程中,“保存时编译”功能会在磁盘上生成文件,但不会将它们添加到项目中。

I then realised the generated files don't actually need to be part of the project as they were before, and why it's better than the WebEssentials solution (excluding the lack of preview window!).

然后我意识到生成的文件实际上不需要像以前那样成为项目的一部分,以及为什么它比 WebEssentials 解决方案更好(不包括缺少预览窗口!)。

回答by Mika?l Mayer

For me, even if Compile-on-save was working (Visual Studio 2013), if someone else tried to run the web project, it would not automatically generate the javascript files. In my project, I included *.jsfiles and *.js.mapfiles to prevent IIS from not taking the new version when I modify the *.tsfiles. But these files are not included in the source control.

对我来说,即使 Compile-on-save 正在工作(Visual Studio 2013),如果其他人尝试运行 Web 项目,它也不会自动生成 javascript 文件。在我的项目中,我包含了*.js文件和*.js.map文件,以防止 IIS 在修改*.ts文件时不采用新版本。但是这些文件不包含在源代码管理中。

What I thus did is that I included the following line at the end of the csprojproject file:

我所做的是在csproj项目文件的末尾包含以下行:

<Target Name="AfterBuild">
  <Exec Command="tsc.exe --sourcemap _core.ts" WorkingDirectory="$(MSBuildProjectDirectory)\js" />
</Target>

where _core.tsis a file in the jsfolder which -- I am sure -- references all files directly or indirectly through headers at its beginning.

_core.ts文件js夹中的文件在哪里——我敢肯定——通过开头的标题直接或间接引用所有文件。

/// <reference path="_dependent.ts" />
...

so that tsc.exeprocesses all the dependent files as well.

这样也可以tsc.exe处理所有相关文件。

回答by Raymond Starkey

I solved this problem by adding the function to the end of the Typescript file. It didn't work when the 'new' function was typed at the top of the page (before the other functions) but when I added it below the last function it worked. Only took three hours!

我通过将函数添加到 Typescript 文件的末尾解决了这个问题。当在页面顶部(在其他函数之前)输入“新”函数时它不起作用,但是当我将它添加到最后一个函数下面时它起作用了。只用了三个小时!

回答by Eduardo Lucas

Beside the steps above, if the compile on save is not working yet, mark your project as the startup project (on VS 2013 solution explorer, right-click, Set as StartUp Project).

除上述步骤外,如果保存时编译还不起作用,请将您的项目标记为启动项目(在 VS 2013 解决方案资源管理器上,右键单击,设置为启动项目)。

This solution was found on Codeplex by nicholasjgreen and is posted on the comments at http://typescript.codeplex.com/wikipage?title=Compile-on-Save.

此解决方案由 nicholasjgreen 在 Codeplex 上找到,并发布在http://typescript.codeplex.com/wikipage?title=Compile-on-Save的评论中。

回答by A. K-R

Have you added the typescript files using drag'n'drop? Then it could be that the build action of the files has the wrong value. Use the property window of the files (F4 or alt + enter) and verify the build action there...

您是否使用拖放添加了打字稿文件?那么可能是文件的构建操作具有错误的值。使用文件的属性窗口(F4 或 alt + enter)并在那里验证构建操作...

回答by prolink007

This feature is a little easier to find using the following method. (VS2015)

使用以下方法更容易找到此功能。(VS2015)

  1. Go to Tools > Options.
  2. Make sure you have "Show all settings"selected. This is a checkbox near the bottom of the window.
  3. Put "typescript" in the search bar and press enter.
  4. Now the list should be filtered. Navigate to the setting: Text editor > Typescript > Project > General.
  5. Now select “Automatically compile TypeScript files which are not part of the project”. Press OK.
  1. 转到工具 > 选项
  2. 确保选择了“显示所有设置”。这是靠近窗口底部的复选框。
  3. 在搜索栏中输入“ typescript”并按回车键。
  4. 现在应该过滤列表。导航到设置:Text editor > Typescript > Project > General
  5. 现在选择“自动编译不属于项目的 TypeScript 文件”。按确定。