4

I have a post build event that runs reflection code over some of my controllers to generate a definition of my routes in typescript. If I activate the TypescriptCompile option in my csproj, the DLL generation will fail if any Typescript file is not correct. Then my post build event will fail because the dll won't exists.

I want to implement the following schema :

  1. Build my dll without typescript compilation
  2. Run my post build event to generate the typescript file with my route definition
  3. Run another post build event to compile / validate ts files fail if they are not correct

The first 2 steps work fine but I'm stuck at the last one. Failing to find a command line to run typescript compilation on a csproj file.

Dreeco
  • 290
  • 4
  • 10

1 Answers1

1

Let's assume that in the post-build event the TypeScript source files are generated under .\tsc-src. And you are using TypeScript 2.0.

You can include a tsconfig.json file in the tsc-src folder with following content:

{
  "compilerOptions": {
    "baseUrl": "",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../tsc-dist",
    "sourceMap": true,
    "target": "es5"
  }
}

Assuming your working directory is in the project folder, if you have already installed TypeScript and tsc is in your PATH, you can add a new post-build event command tsc -p ./tsc-src to compile the TypeScript source files.

Depending on your requirement, you might want to change outDir field to outFile field to emit a single JavaScript file. Here's a pointer to the doc.

yuxhuang
  • 5,279
  • 1
  • 18
  • 13
  • I answer quite late and haven't found the time to try your solution yet. But it seems that with your solution, the hierarchy and organisation of all my ts / js files will be affected. I was looking for an approach csproj based to keep the same organisation. Is there any way with your solution that all of my csproj ts files will output the js in a js file with the same name and in the same folder? (I'm talking about the ["outDir": "../tsc-dist",] instruction) – Dreeco Dec 07 '16 at 14:31
  • @Dreeco I am curious why you would like ts files to be in the same folder? Are you checking them into your repo as well? – yuxhuang Dec 07 '16 at 16:21
  • @Dreeco I think you can just simply remove the `outDir` field to achieve your goal. I have never used a `tsconfig.json` without an `outDir` or `outFile` option though. – yuxhuang Dec 07 '16 at 16:22
  • Yep, they are in the repo. the thing is that the generated ts files (with the routes) are not the only ts files in the project, there is a lot of frontend code as well. I'll give it a try :) – Dreeco Dec 09 '16 at 09:24