简体   繁体   中英

How can I suppress spurious Typescript compilation errors in VS2017?

We have a .Net project with some embedded resources that are xml files with a custom filename extension.

For some reason, on my computer, Visual Studio has suddenly (for the last few days) decided to treat these as TypeScript files and is producing tens of thousands of compile errors on each build.

在此处输入图片说明

The errors don't stop the build, but they do slow it down and make it hard to work out what the real errors are when I have them.

So far I've tried adding

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

to my csproj files, and I've looked at the "Compile on Save" setting for Javascript and it is not enabled. Neither of these fixes seem to work.

We don't have any TypeScript in our project at all.

I'm running Visual Studio 2017 15.5.7

Nobody else in my team is reporting this issue.

How can I suppress spurious Typescript compilation errors in VS2017?

If you can make sure those build errors are Typescript compilation errors, you can try to following methods to suppress Typescript compilation errors:

Add TypeScript transpilation blocked in your project file .csproj(What you have done):

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

Make sure you are including your typescript files as content:

<ItemGroup>
    <Content Include="**\*.ts" />
</ItemGroup>

Add a tsconfig.json file to your project root and make sure compileOnSave is set to false:

"compileOnSave": false,

If all above not help you and you don't have any TypeScript to compiled in our project, you can go to Tools -> Extensions & Updates, and disable Typescript Build for Microsoft Visual Studio .

Hope this helps.

After some experimenting, I discovered how to suppress these messages in my circumstances.

At some point, I had registered a file extension as a type of file to be edited in VS with the XML editor. This is done via: Tools, Options, Text Editor, File Extension

I had added my file extension as an extension that should be edited with the XML editor like below: 文件扩展名关联的设置

After I removed the association, the compile errors stopped appearing.

I don't know what caused Visual Studio 2017 to decide that files to be opened in the XML editor should be treated as TypeScript files and compiled. However, the reason I added the extension no longer applies, so I happily removed it.

I was able to get rid of the TS errors hence the build failures with below settings in VS 2019

Tools > Options > Text Editor > JavaScript/TypeScript > Code Validation > JavaScript Errors > Set the values under JavaScript Errors to False.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM