none
How does MSBuild know to compile TypeScript during Build?

    Question

  • Hi,

    I'm trying to understand when I run Build on my Visual Studio 2017 project how TypeScript (tsc.exe I assume) is reading my tsconfig.json file's settings..

      "compilerOptions": {
        "outDir": "./dist/out-tsc",

    It's working because I'm seeing the latest .js files output there after I run Build.  I'm guessing this is somehow specified in the .csproj?

    I'm just trying to understand how the integration of VS and TypeScript works under the covers.

    Thanks

    Thursday, February 1, 2018 2:52 PM

Answers

  • Hi dat1,

    Thanks for posting here.

    >>>Maybe VS 2017 just sees that tsconfig.json file and transpiles the .ts files automatically when you do a Build? 

    Indeed, what your guess is correct. TypeScript is a first class citizen in the Visual Studio universe. By default, Visual Studio will compile your typescript files whenever you save them. And it’s easy to disable automatic TypeScript compilation. Just add a “TypeScriptCompileBlocked” element to your project’s file and give it a value of “True”. This will prevent Visual Studio from making those extra files:

    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

    For some more details, please check following thread:

    https://stackoverflow.com/questions/40667665/how-to-prevent-visual-studio-2017-from-build-javascript

    Hope this helps.


    MSDN Community Support Please remember to click Mark as Answer. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, February 2, 2018 5:55 AM

All replies

  •  In Visual Studio you can do this by,

    Project > Properties > Build > ensure that the "Compile TypeScript on build"

    It gets build based on the flag you set here.

     

    You can read about the configuration from here


    Thursday, February 1, 2018 3:14 PM
  • Hi, I'm using VS 2017 and don't see that option.

    Thursday, February 1, 2018 4:32 PM
  • If you look at the bottom there is TypeScript Build

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (kokkisajee) or Facebook (sajeetharan) profile for Sajeetharan at Stack Overflow, Q&A for professional and enthusiast programmers

    Thursday, February 1, 2018 5:12 PM
  • Thanks but I'm not seeing that option. Here's my entire "Build" property page

    I do have a "TypeScript Build" tab besides my "Build" tab.  All the properties are disabled on it since I have tsconfig.json file.  Maybe VS 2017 just sees that tsconfig.json file and transpiles the .ts files automatically when you do a Build?  Just a guess at this point.  


    • Edited by dat1 Thursday, February 1, 2018 7:16 PM
    Thursday, February 1, 2018 7:10 PM
  • Hi dat1,

    Thanks for posting here.

    >>>Maybe VS 2017 just sees that tsconfig.json file and transpiles the .ts files automatically when you do a Build? 

    Indeed, what your guess is correct. TypeScript is a first class citizen in the Visual Studio universe. By default, Visual Studio will compile your typescript files whenever you save them. And it’s easy to disable automatic TypeScript compilation. Just add a “TypeScriptCompileBlocked” element to your project’s file and give it a value of “True”. This will prevent Visual Studio from making those extra files:

    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

    For some more details, please check following thread:

    https://stackoverflow.com/questions/40667665/how-to-prevent-visual-studio-2017-from-build-javascript

    Hope this helps.


    MSDN Community Support Please remember to click Mark as Answer. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, February 2, 2018 5:55 AM
  • Thanks! The article you pointed me to in another post https://blog.sstorie.com/0-60-with-angular-2-and-visual-studio-part-2/ stated it clearly...

     "Now even with this you'll still find that Visual Studio will compile the typescript files when you build the project"..."By default VS will compile your typescript code automatically whenever you build the project the files are associated with"

    Saturday, February 3, 2018 2:50 AM