禁用 MSBuild TypeScript 编译

对于诸如 ASP.NET MVC5之类的 VisualStudio 项目,如何禁用在构建/调试时编译 TypeScript 文件?

我目前有 tsconfig.json compileOnSavebuildOnSave设置为假。是否需要向项目 .csproj添加一些内容以确保它不被编译?

在调试 ASP.NET MVC5项目时,它会编译所有的 .ts文件。

谢谢你的帮助。

35466 次浏览

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

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

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

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.

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

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.

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>