How to include TypeScript files when publishing? How to include TypeScript files when publishing? typescript typescript

How to include TypeScript files when publishing?


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.


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.


First, you can have a look at your published directory to see if the files are there.You can reproduce this locally with MSBuild:

msbuild path/to/your/solution.sln-or-project.csproj /p:OutputPath=path/to/outputFolder /p:Configuration=Release

After run this command, you can search for your .ts files in the folder:

outputFolder/_bin/PublishedWebsites/YourProjectName/

All outputs of a project are copied to the output directory during the execution of the MSBuild task "CopyFilesToOutputDirectory".

If after run the MSBuild command your .ts files that are marked as "Copy Always" or "Copy If Newer" are still not being copied, chances are that your project file does not import the common targets file provided by Microsoft, in which the task "CopyFilesToOutputDirectory" is defined.

In which case, edit your .csproj file, adding an import clause to the appropriate file, as below:

<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

Try run the MSBuild command again after the Microsoft.WebApplication.targets has been imported, and the files marked to be published should now be in the output folder.