无法在 Visual Studio 2012 中编译 TypeScript 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13051515/
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
Cannot compile TypeScript files in Visual Studio 2012
提问by Arrow
I downloaded and installed TypeScript extension for VS 2012, I got my first sample compiles by manually dragging the ts file onto the tsc.exe file!because no other way to compile the file will work.
我下载并安装了 VS 2012 的 TypeScript 扩展,通过手动将 ts 文件拖到 tsc.exe 文件上,我得到了我的第一个示例编译!因为没有其他方法可以编译文件。
I don't want to manually do this everytime I want to debug a page! I have read about 5 articles on the web and none of the solutions work. I've tried adding TypeScript compiler to PATH in Windows, I've tried downloading and installing via Nuget Package Manager the Sholo thing, I've tried these pages:
我不想每次要调试页面时都手动执行此操作!我在网上阅读了大约 5 篇文章,但没有一个解决方案有效。我试过在 Windows 中将 TypeScript 编译器添加到 PATH,我试过通过 Nuget 包管理器下载和安装 Sholo 的东西,我试过这些页面:
- Using TypeScript in cshtml files
- Visual Studio TypeScript Options
- Debugging TypeScript code with Visual Studio
- Cannot compile typescript using tsc node module
- TypeScript - Visual Studio - d3
- Visual Studio 2012 TypeScript project ignoring two files during compile
- TypeScript / Visual Studio 2012 / Compilation parameters
- Using TypeScript in an existing Visual Studio Web Site project
- Visual Studio TypeScript Options
- Compile generated files in Visual Studio
- 在 cshtml 文件中使用 TypeScript
- Visual Studio TypeScript 选项
- 使用 Visual Studio 调试 TypeScript 代码
- 无法使用 tsc 节点模块编译打字稿
- 打字稿 - Visual Studio - d3
- Visual Studio 2012 TypeScript 项目在编译期间忽略两个文件
- TypeScript / Visual Studio 2012 / 编译参数
- 在现有的 Visual Studio 网站项目中使用 TypeScript
- Visual Studio TypeScript 选项
- 在 Visual Studio 中编译生成的文件
And not a single solution has worked.
并且没有一个解决方案奏效。
I have even downloaded and installed the Web Essentials plugin for Visual Studio and gone to Options menu, then selected "Compile all TypeScript files on Build = True" and "Compile TypeScript on Save = True" - but nothing works.
我什至下载并安装了 Visual Studio 的 Web Essentials 插件,然后转到“选项”菜单,然后选择“在 Build = True 时编译所有 TypeScript 文件”和“在 Save = True 时编译 TypeScript”——但没有任何效果。
I've read the entire TypeScript website, the specification, and even their discussion tab on the codeplex site.
我已经阅读了整个 TypeScript 网站、规范,甚至他们在 codeplex 站点上的讨论选项卡。
How can I get TypeScript to compile when I save changes to the .ts
file orwhen I press F5/Debug/Build?
当我保存对.ts
文件的更改或按 F5/Debug/Build 时,如何让 TypeScript 进行编译?
*I don't really want any third-party scripts/plugins, etc unless it's absolutely necessary. I've seen a couple of them and it's just ... there's no point. I might as well just write pure JavaScript.
*除非绝对必要,否则我真的不想要任何第三方脚本/插件等。我看过其中的几个,只是……没有意义。我还不如只写纯 JavaScript。
回答by ozz
You have to ensure that the BuildAction must be TypeScriptCompile for your .ts files. I've added these lines to end of the (.csproj) project file. (Before closing Project tag) And It seems working.
您必须确保 .ts 文件的 BuildAction 必须是 TypeScriptCompile。我已将这些行添加到 (.csproj) 项目文件的末尾。(在关闭 Project 标签之前)而且它似乎有效。
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<TypeScriptTarget>ES3</TypeScriptTarget>
<TypeScriptIncludeComments>true</TypeScriptIncludeComments>
<TypeScriptSourceMap>true</TypeScriptSourceMap>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<TypeScriptTarget>ES3</TypeScriptTarget>
<TypeScriptIncludeComments>false</TypeScriptIncludeComments>
<TypeScriptSourceMap>false</TypeScriptSourceMap>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
</PropertyGroup>
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
回答by ryan
I had a similar problem when I renamed my .js files to .ts. You have to right click and add a new TypeScript File to your project in order for your .csproj to recognize that the TypeScript compiler should be used on this .ts file.
当我将 .js 文件重命名为 .ts 时,我遇到了类似的问题。您必须右键单击并将一个新的 TypeScript 文件添加到您的项目中,以便您的 .csproj 识别应在此 .ts 文件上使用 TypeScript 编译器。
You will know it is correct when you see the arrow to expand the .ts file.
当您看到展开 .ts 文件的箭头时,您就会知道它是正确的。
回答by Fenton
If you change a .js
file into a .ts
file, you can go to the properties panel in Visual Studio and change the Build Action to TypeScriptCompile. This is what is missing when you change a file. This can save you from deleting and re-adding files.
如果将.js
文件更改为.ts
文件,则可以转到 Visual Studio 中的属性面板,将 Build Action 更改为 TypeScriptCompile。这是更改文件时缺少的内容。这可以使您免于删除和重新添加文件。
回答by Vladimir
I had the same problem. I couldn't add new .ts file to the project. After renaming from .js to .ts file was not compiled. It even was not compiled using tsc in command line.
我有同样的问题。我无法向项目添加新的 .ts 文件。从 .js 重命名为 .ts 文件后没有编译。它甚至不是在命令行中使用 tsc 编译的。
BUT! After recreating the file in windows explorer it was compiled successfully. And after manually creating file in windows explorer (not Visual Studio) in Scripts folder and including it to the project - all WORKS. I couldn't detect changes between these two files. But if you create text file in explorer, rename it to .ts and after that include in project and set file's Build Action to TypeScriptCompile - it works.
但!在 Windows 资源管理器中重新创建文件后,它已成功编译。在 Scripts 文件夹中的 Windows 资源管理器(不是 Visual Studio)中手动创建文件并将其包含到项目中之后 - 所有的工作。我无法检测到这两个文件之间的变化。但是,如果您在资源管理器中创建文本文件,请将其重命名为 .ts,然后将其包含在项目中并将文件的 Build Action 设置为 TypeScriptCompile - 它可以工作。
回答by Gluip
plug
插头
I create a NuGet package that adds a afterbuild target to your project so all the included ts files are compiled to js.
我创建了一个 NuGet 包,该包将一个 afterbuild 目标添加到您的项目中,以便将所有包含的 ts 文件编译为 js。
Install-Package TypeScript.Compile
安装包 TypeScript.Compile
回答by cheesus
Please check if you have invalid TypeScript. There are some TypeScript errors that don't show up in the Error List, but they prevent TypeScript Compile-On-Save and show a Output generation failed
message in the Visual Studio status bar.
请检查您是否有无效的 TypeScript。有一些 TypeScript 错误不会显示在错误列表中,但它们会阻止 TypeScript Compile-On-Save 并Output generation failed
在 Visual Studio 状态栏中显示一条消息。
These are the TypeScript errors that can cause this:
这些是可能导致这种情况的 TypeScript 错误:
export
ing a class which is not inside of a module (v 0.9.5).
export
一个不在模块内部的类(v 0.9.5)。
Please let me know if there are more such errors, I'll add them here.
如果有更多这样的错误,请告诉我,我会在这里添加它们。
回答by Yasin Kilicdere
I had the same problem. I updated web essentials extention and problem is solved. If you have web essentials extention, you can try that.
我有同样的问题。我更新了 Web Essentials 扩展,问题解决了。如果您有 Web Essentials 扩展,则可以尝试。