typescript VS2012 中的打字稿:(自动)从 .ts 生成 .js
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12683820/
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
Typescript in VS2012: (automatically) generating .js from .ts
提问by YS.
I've added file1.tsand I can see there's a dependent to it - namely file1.js.
我已经添加file1.ts,我可以看到它有一个依赖项 - 即file1.js.
I notice that any changes I made to file1.ts- file1.jsdoesn't get automatically re-generated.
我注意到我所做的任何更改file1.ts-file1.js不会自动重新生成。
The only workaround I have at the moment is by calling tsc.exe- as part of pre-build event.
我目前唯一的解决方法是调用tsc.exe- 作为预构建事件的一部分。
My question is - are there any better workaround or maybe a setting somewhere I might've missed ?
我的问题是 - 有没有更好的解决方法或者我可能错过的某个地方的设置?
回答by Lakerfield
Install the Web Essentials 2012 extension in Visual Studio 2012.
在 Visual Studio 2012 中安装 Web Essentials 2012 扩展。
It will re-generate the .js file on every save of the .ts file.
它会在每次保存 .ts 文件时重新生成 .js 文件。
http://visualstudiogallery.msdn.microsoft.com/07d54d12-7133-4e15-becb-6f451ea3bea6
http://visualstudiogallery.msdn.microsoft.com/07d54d12-7133-4e15-becb-6f451ea3bea6
回答by Ralph de Ruijter
You have to add a BeforeBuild target to your ASP.NET application's CSPROJ:
您必须向 ASP.NET 应用程序的 CSPROJ 添加一个 BeforeBuild 目标:
<Target Name="BeforeBuild">
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript##代码##.8.0.0\tsc" @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
tip: edit your csproj file with notepad.
提示:使用记事本编辑您的 csproj 文件。
回答by guy schaller
Support for typescript has been removed from Web Essentials 2012 v3
已从 Web Essentials 2012 v3 中删除对 typescript 的支持
you now need to download typescript support directly from microsoft:
您现在需要直接从微软下载打字稿支持:
http://www.microsoft.com/en-us/download/details.aspx?id=34790
http://www.microsoft.com/en-us/download/details.aspx?id=34790
回答by mohamed hegazy
In Visual Studio you need to invoke the build process for your files to be generated. The playground does not use the same build system, and it triggers the compilation once the source changes, so this is why you are seeing the difference in behavior.
在 Visual Studio 中,您需要为要生成的文件调用构建过程。Playground 不使用相同的构建系统,一旦源代码更改,它就会触发编译,所以这就是您看到行为差异的原因。
回答by Gluip
plug
插头
You can use Install-Package TypeScript.Compile to add a afterbuild target that compiles all TypeScript files included in your project.
您可以使用 Install-Package TypeScript.Compile 添加一个 afterbuild 目标,该目标编译项目中包含的所有 TypeScript 文件。

