Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typescript for web forms

Is typescript supported on web forms?

I have an existing asp.net 4.5 web forms project where typescript does not seem to be working. I cannot create a new file, but even if I rename an existing to .ts it does not seem to be working. No build, no intellisense, nothing!

like image 725
George Mavritsakis Avatar asked Oct 25 '12 13:10

George Mavritsakis


2 Answers

Found the answers to my problems:

  1. I was trying to find "Typescript file" in Web folder of the "Add New Item" dialog, although it is in the "Visual C#" folder ..... Why?

  2. Unless you have a .ts file created with "Add New Item" in your project, the option "TypeScriptCompile" on the "Build Action" of the file properties is not available and it raises an exception. After the first file is created, then you find this option and can manually set it to a .ts file.

  3. The option "Typescript file" is not available in the "Add File" options unless you have a .ts file created with "Add New Item" in your project and you are in a "Scripts" folder (if you name differently the folder where you want to add this file, this option wont be available). Of course you can add a .ts file from "Add New Item".

  4. You cannot easily create a ts file by your own, you must use "New Typescript file" from menu. That is because: A) The code page of the file must not be Unicode (I was trying to figure out that problem for many hours). if you try to compile a unicode .ts file with tsc, nothing happens!! After I saved the .ts file as Greek(Windows) - in my case-, everything worked fine! B) The .csproj properties that must be set for each file to work correctly are quite complex. (I was trying to create a .ts file starting from a .js file and renaming afterwards.... and then playing with .csproj)

like image 152
George Mavritsakis Avatar answered Sep 21 '22 22:09

George Mavritsakis


I just created a new Web Application using web forms (empty project).

I found I have to add the Target to my project file...

   <Target Name="BeforeBuild">
    <Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
  </Target>

You need to right-click and select "Unload project", then right-click and select "Edit". This block can go right at the end, just before the </Project> tag.

I didn't have any problems adding a TypeScript file in Visual Studio 2012.

like image 25
Fenton Avatar answered Sep 19 '22 22:09

Fenton