jausel
jausel

Reputation: 615

Typescript file will not compile when I build solution (Visual Studio 2012)

When I try to build my solution in Visual Studio 2012, the javascript file is not generated. It only happens for a specific file.

Upvotes: 3

Views: 6520

Answers (5)

Jim W
Jim W

Reputation: 5016

I found that for a fresh project my .csproj file was missing some important lines - no idea why, but easy fix which I talk about it a bit in my TypeScript blog:

...despite the “Build Action” for the .ts file being correctly set to “TypeScriptCompile”. To fix this I had to

Right click on the project in solution explorer and choose Unload Project Right click the project and choose Edit Add the bold lines from the code below in their relevant sections

<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” />

The import line should go towards the end of the project file where other Import elements appear. After making this change my .ts files compiled properly. It would appear to me that this bug was taken care of in subsequent releases of TypeScript as it is not a problem with Visual Studio 2013 and TS 1.4.

Right click on the project in the solution explorer and reload the project.

Upvotes: 2

Mika&#235;l Mayer
Mika&#235;l Mayer

Reputation: 10711

The current Typescript plugin for VS2013 compiles only on save, not on build. This can be a pain if some typescript files are edited outside or if the project has to be rebuilt from scratch.

I added the following at the end of the csproj, in the <Target Name="AfterBuild"> section.

<Exec Command="tsc.exe -target ES5 --sourcemap _core.ts"
    WorkingDirectory="$(MSBuildProjectDirectory)\js" />

where js is the directory where the typescript files are and _core.ts is the main typescript referencing all other typescripts in its header.

Now even if a co-workers fetches the project, it will automatically rebuild all javascript files.

Upvotes: 0

jausel
jausel

Reputation: 615

The problem for me was that the file's Build Action was set incorrectly.

Go to the file's properties and make sure that it is set to TypeScriptCompile.

File Properties: TypeScriptCompile

Upvotes: 8

basarat
basarat

Reputation: 276085

Install Web Essentials http://visualstudiogallery.msdn.microsoft.com/07d54d12-7133-4e15-becb-6f451ea3bea6

It has a setting for compile on build: enter image description here

Upvotes: 1

zawisza
zawisza

Reputation: 1123

Install the TypeScript for Visual Studio plugin you will be able to see the JS code as soon as you save the TS file. You can also debug the JS this way.

Upvotes: 0

Related Questions