Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include TypeScript files when publishing?

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)

like image 847
Geir Sagberg Avatar asked Jun 20 '14 07:06

Geir Sagberg


People also ask

What is a TypeScript in publishing?

The term 'typescript'—sometimes abbreviated in a bibliographical or publishing context to 'TS', 'Ts' or 'ts'—means a page, or series of pages, of text produced by the use of a typewriter. ... From: typescript in A Dictionary of English Manuscript Terminology 1450–2000 »

How do I add a TypeScript package?

You can use npm to install TypeScript globally, this means that you can use the tsc command anywhere in your terminal. To do this, run npm install -g typescript . This will install the latest version (currently 4.7).


2 Answers

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.

like image 187
Stanislav Berkov Avatar answered Sep 21 '22 20:09

Stanislav Berkov


Based on Stas Berkov's answer, I am conditionally including the .ts files only when the source maps are generated (as configured in the TypeScript Build tab of the project's properties).

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

I placed this as the last element in <Project> of the .csproj file.

like image 44
bdimag Avatar answered Sep 21 '22 20:09

bdimag