简体   繁体   English

如何在 VS2017 中抑制虚假的 Typescript 编译错误?

[英]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.我们有一个 .Net 项目,其中包含一些嵌入式资源,这些资源是具有自定义文件扩展名的 xml 文件。

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.出于某种原因,在我的计算机上,Visual Studio 突然(最近几天)决定将这些文件视为 TypeScript 文件,并且在每次构建时都会产生数以万计的编译错误。

在此处输入图片说明

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.到我的 csproj 文件,我查看了 Javascript 的“保存时编译”设置,但它没有启用。 Neither of these fixes seem to work.这些修复似乎都不起作用。

We don't have any TypeScript in our project at all.我们的项目中根本没有任何 TypeScript。

I'm running Visual Studio 2017 15.5.7我正在运行 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? 如何抑制VS2017中的虚假Typescript编译错误?

If you can make sure those build errors are Typescript compilation errors, you can try to following methods to suppress Typescript compilation errors: 如果可以确保这些构建错误是Typescript编译错误,则可以尝试以下方法来抑制Typescript编译错误:

Add TypeScript transpilation blocked in your project file .csproj(What you have done): 在项目文件.csproj中添加被阻止的TypeScript编译(已完成):

<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: 将tsconfig.json文件添加到项目根目录,并确保将compileOnSave设置为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 . 如果上述所有操作均无济于事,并且您的项目中没有任何TypeScript可以编译,则可以转到Tools-> Extensions&Updates,并禁用Microsoft Visual Studio的Typescript Build

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. 在某个时候,我已经将文件扩展名注册为要在XML中使用XML编辑器编辑的文件类型。 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: 我已将文件扩展名添加为应使用XML编辑器进行编辑的扩展名,如下所示: 文件扩展名关联的设置

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. 我不知道是什么原因导致Visual Studio 2017决定应在XML编辑器中打开的文件应视为TypeScript文件并进行编译。 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我能够摆脱 TS 错误,因此在 VS 2019 中使用以下设置导致构建失败

Tools > Options > Text Editor > JavaScript/TypeScript > Code Validation > JavaScript Errors > Set the values under JavaScript Errors to False.工具 > 选项 > 文本编辑器 > JavaScript/TypeScript > 代码验证 > JavaScript 错误 > 将JavaScript 错误下的值设置为 False。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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