How to disable TypeScript compilation in .Net Core projects?

放肆的年华 提交于 2019-11-27 02:34:15

问题


I have a Visual Studio 2015 ASP.Net Core project that contains a folder of typescript files.

My question is how can I prevent VS from trying to compile the TypeScript files? I don't want them compiled, either on save or build.

I have tried added the project setting below, but it doesn't seem to have any impact.

<PropertyGroup>
  <TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled>
</PropertyGroup>

Currently VS is throwing an error, tsc.exe exited with code 1, but as stated, I don't want the TS compiler to run at all.

I can disable the typescript.targets that VS uses, but that's not practical, because I need it for other projects.


回答1:


I spent some time digging around in the C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets file, and I found a support property that seems to do the job.

Add this property to the project, by editing the project file directly and adding this property group:

<PropertyGroup>
  <!-- Makes the TypeScript compilation task a no-op -->
  <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>

EDIT: @Chopin pointed out in the comments that the official doc for this and other Typescript MSBuild related options is here.




回答2:


this trick indeed works for new version of MSBuild. However if you still have older versions of MSBUild, on a build server or so. You also want to remove these lines from the csproj file.

  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />

   <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />

Regards



来源:https://stackoverflow.com/questions/39176586/how-to-disable-typescript-compilation-in-net-core-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!