Disable MSBuild TypeScript Compile

asp.netVisual StudioTypescriptMsbuild

asp.net Problem Overview


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.

asp.net Solutions


Solution 1 - asp.net

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>.

Solution 2 - asp.net

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.

Solution 3 - asp.net

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

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

Solution 4 - asp.net

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\**" />

Solution 5 - asp.net

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.

Solution 6 - asp.net

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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexander StaroselskyView Question on Stackoverflow
Solution 1 - asp.netFionnView Answer on Stackoverflow
Solution 2 - asp.netDaciliView Answer on Stackoverflow
Solution 3 - asp.netPrasad BhaleraoView Answer on Stackoverflow
Solution 4 - asp.netAstravagrantView Answer on Stackoverflow
Solution 5 - asp.netMarkus Knappen JohanssonView Answer on Stackoverflow
Solution 6 - asp.netSam AlekseevView Answer on Stackoverflow