0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

is references.d.ts a file you made? or do I have to list each ts file I want compiling? references.d.ts looks like a definition file, but Im not sure how it is made? Thanks
It is a typescript project file which reference all typescript files; You should try use tsconfig.json if you are using TypeScript 1.8. You don't need to use typescript project file if you don't mind passing all files to the tsc command line. E.g., tsc $(ProjectDir)\Scripts\file1.ts $(ProjectDir)\Scripts\file2.ts ...
Sorry for the confusion, tsconfig.json replace the need for references.d.ts, they both meant to organize typescript files. Please refer to typescriptlang.org/docs/handbook/tsconfig-json.html for more information.
And you can learn how to use TypeScript command line from typescriptlang.org/docs/tutorial.html and typescriptlang.org/docs/handbook/compiler-options.html
You can add it to your path, right? Typically, tsc is located at C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.