Visual Studio 2012 中的 TypeScript 未编译

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

TypeScript in Visual Studio 2012 not compiling

visual-studiovisual-studio-2012typescript

提问by StockBreak

I have installed TypeScript(v0.9.1.1) on my Visual Studio 2012 installation but I cannot make it compile my .tsfiles during build (see screenshots below).

我已经在我的 Visual Studio 2012 安装上安装了TypeScript(v0.9.1.1),但我不能让它.ts在构建过程中编译我的文件(见下面的截图)。

I have already tried a lot of different solutions posted here but none of them worked for me.

我已经尝试了很多不同的解决方案,但没有一个对我有用。

Please note that I can create a TypeScript project, the problem is that Visual Studio is not compiling/creating the .jsfile.

请注意,我可以创建一个 TypeScript 项目,问题是 Visual Studio 没有编译/创建.js文件。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by stride

Try to introduce error in your typescript file and make a build of the project. Does it show up error pane?

尝试在您的打字稿文件中引入错误并构建项目。它是否显示错误窗格?

Also the js files are not part of the solution. Do you look for them on disk ?

此外,js 文件不是解决方案的一部分。你在磁盘上寻找它们吗?

Also check that your project file has following entries in it. Along the lines more less:

还要检查您的项目文件中是否包含以下条目。沿线更多更少:

<ItemGroup>
    <TypeScriptCompile Include="app.ts" />
  </ItemGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES3</TypeScriptTarget>
    <TypeScriptRemoveComments>false</TypeScriptRemoveComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
    <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptTarget>ES3</TypeScriptTarget>
    <TypeScriptRemoveComments>true</TypeScriptRemoveComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
    <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
  </PropertyGroup>
  <Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />

回答by Marek Pavelek

as you can see in patch notes for version 0.9.1

正如您在 0.9.1 版的补丁说明中所见

The .js files are no longer part of the project by default. Starting with 0.9.1, we don't nest them under the TypeScript files. This is more of a visual change, but it also lets us manage the .js files behind the scenes a bit cleaner.

默认情况下,.js 文件不再是项目的一部分。从 0.9.1 开始,我们不会将它们嵌套在 TypeScript 文件下。这更像是一种视觉上的变化,但它也让我们在后台更清晰地管理 .js 文件。

So just create a TypeScript file(in your case app.ts) and then simply add reference to your page

因此,只需创建一个 TypeScript 文件(在您的情况下为 app.ts) ,然后只需添加对您的页面的引用

<head>
  <script src="app.js"></script>
</head>

回答by t_plusplus

I solved it by right click on the typescript file, select properties, and then set the BuildAction to none as shown here:

我通过右键单击打字稿文件,选择属性,然后将 BuildAction 设置为 none 解决了这个问题,如下所示:

enter image description here

在此处输入图片说明

回答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 failedmessage 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 错误:

  • exporting 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.

如果有更多这样的错误,请告诉我,我会在这里添加它们。