8

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!

1
  • 1
    Actually, I found that the problem starts from the fact that although for MVC projects the "build action" property of a .ts file is "TypeScriptCompile", this option is not available on web forms projects. I event entered this by hand but it raised an error. Commented Oct 25, 2012 at 13:59

2 Answers 2

7

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)

Sign up to request clarification or add additional context in comments.

2 Comments

@user1749204 He means make sure the code page is not Unicode CP_UNICODE.
@george-mavritsakis - is/was your Web forms a Web Site or Web Application? I'm trying to use Typescript in a Web Site but I don't have a .csproj to add a "build action".
5

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.

3 Comments

What happens if you manually run tsc on the file: tsc pathtofile.ts?
Nothing happens!!!! Sohnee, I found that it was a code page issue.... Check below. Thanks for your support!
I think "Install-Package TypeScript.Compile" can do too .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.