如何添加打字稿到现有Asp.Net MVC项目? [英] How do I add typescript to an existing Asp.Net MVC project?

查看:110
本文介绍了如何添加打字稿到现有Asp.Net MVC项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我爱打字稿背后的想法,但似乎无法弄清楚如何将其纳入一个ASP.Net MVC项目。我已经安装了Visual Studio的扩展,但我似乎无法找到如何添加 *例子或文件。TS 它编译成<$ C $文件C> *。JS 文件。

I love the idea behind typescript, but can't seem to figure out how to include it in an ASP.Net MVC project. I've already installed the Visual Studio extension, but I can't seem to find an example or documentation on how to add *.ts files which compile into *.js files.

编辑:其实,我应该复制的Win8的例子 .jsproj 包括和手柄 .TS 文件的方式?或将只对HTML / JS的Win8项目的工作?

Actually, should I replicate the way that the Win8 example .jsproj includes and handles .ts files? Or will that only work for HTML/JS Win8 projects?

推荐答案

警告:这个答案是现在相当过时,因为打字稿和MVC都自这个答案显著改变。以后我会尝试更新。 - 丰富的codeR

Warning: This answer is now fairly dated, as both Typescript and MVC has changed significantly since this answer. I'll try an update later. - Richcoder

感谢 Sohnee 答案。

您可以使用Add>新建项目对话框打字稿文件添加到现有项目。

请注意,打字稿文件项不驻留在Web组下但根据它在这种情况下的Visual C#父。

You can add TypeScript files to an existing project using the Add > New Item dialog. Please note that the 'Typescript File' item doesn't reside under the Web group but under it's parent in this case Visual C#.

这应该添加一个打字稿文件和Visual Studio将做休息。

This should add a TypeScript file and Visual Studio will do the rest.

然后,你需要将这些行添加到项目文件:

Then you need to add these lines to the project file:

 <ItemGroup>
    <AvailableItemName Include="TypeScriptCompile" />
 </ItemGroup>
 <ItemGroup>
    <TypeScriptCompile Include="$(ProjectDir)\**\*.ts" />
 </ItemGroup>
 <Target Name="BeforeBuild">
    <Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; -target ES5 @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" IgnoreExitCode="true" />
 </Target>

它的工作完美的我,但如果您遇到任何问题,请评论。

It worked perfectly for me, but please comment if you run into any issues.

这篇关于如何添加打字稿到现有Asp.Net MVC项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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