Cannot compile TypeScript files in Visual Studio 2012

前端 未结 7 1169
长发绾君心
长发绾君心 2020-12-29 08:45

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

相关标签:
7条回答
  • 2020-12-29 09:24

    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.

    You will know it is correct when you see the arrow to expand the .ts file.

    enter image description here

    0 讨论(0)
  • 2020-12-29 09:24

    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.

    0 讨论(0)
  • 2020-12-29 09:25

    I had the same problem. I updated web essentials extention and problem is solved. If you have web essentials extention, you can try that.

    0 讨论(0)
  • 2020-12-29 09:28

    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.

    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.

    0 讨论(0)
  • 2020-12-29 09:29

    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.

    These are the TypeScript errors that can cause this:

    • exporting a class which is not inside of a module (v 0.9.5).

    Please let me know if there are more such errors, I'll add them here.

    0 讨论(0)
  • 2020-12-29 09:33

    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.

     <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" />
    
    0 讨论(0)
提交回复
热议问题