0
votes

I have a Visual Studio project that uses Typescript. This projects gets compiled into a dll and then referenced in the main project. This works fine for all normally compiled files, but I am hitting an issue when it comes to transpiled javascript files.

The sub project has the following in the .csproj file

<Target Name="AfterClean">
    <ItemGroup>
      <EmbeddedResource Include="**\*.html;**\*.cshtml;**\*.css;**\*.js;**\*.map;**\*.jpg;**\*.png" />
    </ItemGroup>
  </Target>

This will include the .js files in the project when a Rebuild Solution is run, but it will not include the .js files when a normal build or a "Run" from Visual studio is used.

I believe the issue is to do with timings, I want the embedding to occur after the typescript transpile has happened, but before the dll is included in the main project.

I have tried the following options "BeforeBuild", "AfterBuild", "BeforeResolveReference", "AfterResolveReferences", "BeforeResGen" and "AfterResGen". - Found from a msdn article here

Ideally I would like to add a DependsOnTargets=TypeScript compile to my embedding task so it forced the embed to happen after the transpile, but the typescript compile does not appear to be a target as it just appears like this in the .csproj file, so I don't believe this is possible

<ItemGroup>
    <TypeScriptCompile Include="app\app.module.ts" />
    ...
 </ItemGroup>

Any ideas would be greatly appreciated

(I am using Visual Studio 2015 Update 3 and Typescript 1.8)

EDIT: The build server does not have tsc on the PATH so I am unable to call tsc from a prebuild event

1

1 Answers

1
votes

I have tried to do similar thing, the solution works for me is use TypeScript command line to compile TypeScript in the pre-build event.

<PropertyGroup>
    <PreBuildEvent>
        tsc $(ProjectDir)\Scripts\references.d.ts
        // or compile tsconfig.json if you use TypeScript 1.8
        // tsc --project $(ProjectDir)\Scripts\
    </PreBuildEvent>
</PropertyGroup>

Then add following target element for BeforeBuild:

<Target Name="BeforeBuild" DependsOnTargets="PreBuildEvent">
    <ItemGroup>
        <EmbeddedResource Include="**\*.js" />
    </ItemGroup>
</Target>

You can find more information about tsconfig.json here.