How to include TypeScript files when publishing?

Geir Sagberg picture Geir Sagberg · Jun 20, 2014 · Viewed 10k times · Source

I have an MVC 5.1 web application where I have recently started using TypeScript. I want to use sourcemapping, so I have included both the .ts, .js and .js.map-files in the project.

When I publish the application (to e.g. file system or Azure), only the .js and .js.min files are copied, not the .ts-file. This means that I do not get source mapping on the published site.

The TypeScript file has "Build Action": "TypeScriptCompile", and I have tested "Copy to Output Directory" both with "Do not copy" and "Copy always", still the .ts-file is not published.

How can I include the .ts-files when publishing my application?

(I am using VS2013 Update 2 with TypeScript 1.0.1 and Web Essentials 2013 for Update 2)

Answer

Stanislav Berkov picture Stanislav Berkov · Oct 2, 2014

I achieved this by editing project (csproj) file. I included .ts (they are stored in TypeScriptCompile item) files into Content item i.e.

  <Target Name="AddTsToContent" AfterTargets="CompileTypeScript" Condition="'$(BuildingProject)' != 'false'">
     <ItemGroup>
        <Content Include="@(TypeScriptCompile)" Condition="'$(Configuration)'=='Debug'"/>
     </ItemGroup>
  </Target>

Note: Because of the condition, this includes the TypeScript content only for the Debug build configuration.