Disable MSBuild TypeScript Compile

For a Visual Studio projects such as a ASP.NET MVC5, how do you disable compiling of TypeScript files on build/debug?

I currently have tsconfig.json compileOnSave and buildOnSave set to false. Does something need to be added to the projects .csproj to ensure it isn’t compiled?

When debugging the ASP.NET MVC5 project, it compiles all .ts files.

Thank you for any help you can provide.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Add the property <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> to a PropertyGroup in your csproj file (I added it under the Configuration label). This should disable all msbuild based TS compilation.

With this setting enabled you shouldn’t need the tsconfig.json settings compileOnSave/buildOnSave.

If you are on an older version of Visual Studio (I had implicitly thought about VS 2017 or xproj with 2015), the property may be <TypeScriptEnabled>false</TypeScriptEnabled>.

Method 2

I had all of this configured, but it still did not fix the issue
(in visual studio 2019).
I added additionally this:

 <TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled>

and restarted the visual studio. After that, it started working for me.

Method 3

For Visual Studio 2015, adding below line under PropertyGroup helped me.

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

Method 4

None of the other solutions worked for me and this one caused an error on project load (VS 2019 – 16.9.4)

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>  // doesn't work for me

Another way of doing the same thing (albeit with very minor overhead) is to just remove all your TS from the compilation index.

<TypeScriptCompile Remove="*" />

I use this for avoiding compilation of node modules, like so:

<TypeScriptCompile Remove="node_modules**" />

Method 5

I had this issue, tested all the things that was posted here without success,

But after adding this, things worked:

<TypeScriptToolsVersion>3.9</TypeScriptToolsVersion>

Seems like the version that I was using did compile no matter the settings.

Method 6

Next approach worked for me (.NET 6, VS2022, ASP.NET Core + Angular project).
Add this setting to your *.csproj file:

<PropertyGroup>
        <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x