typescript 防止 Visual Studio 尝试解析打字稿

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38593453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:41:16  来源:igfitidea点击:

Prevent Visual Studio from trying to parse typescript

visual-studiotypescript

提问by tt9

Working on a project using Visual Studio as my IDE. It has an API component written in C#, and a webserver component that uses TypeScript.

使用 Visual Studio 作为我的 IDE 处理项目。它有一个用 C# 编写的 API 组件和一个使用 TypeScript 的网络服务器组件。

I am using webpack to deal with the typescript compilation and would like to remove the Visual Studio build step from the typescript files.

我正在使用 webpack 处理打字稿编译,并希望从打字稿文件中删除 Visual Studio 构建步骤。

Normally I wouldn't care if it was building them, but I am using Typescript > 1.8.4 which has language features that Visual Studio cannot understand which is making Visual Studio throw errors and prevent compilation. I found a workaround for this in this github issue threadbut I have other developers cross team who are working on this and trying to coordinate a hack to make code among them will not work.

通常我不会在意它是否正在构建它们,但我使用的是 Typescript > 1.8.4,它具有 Visual Studio 无法理解的语言功能,这使 Visual Studio 抛出错误并阻止编译。我在这个 github 问题线程中找到了一个解决方法,但我有其他跨团队的开发人员正在处理这个问题,并试图协调一个黑客来使他们之间的代码不起作用。

I have also tried removing the typescript imports line from the .csproj file, but whenever I add a new ts file, it adds the line back in.

我还尝试从 .csproj 文件中删除 typescript 导入行,但是每当我添加新的 ts 文件时,它都会重新添加该行。

Is there a way to completely shut down the typescript compilation/parsing step in Visual Studio and prevent it from coming back?

有没有办法完全关闭 Visual Studio 中的打字稿编译/解析步骤并防止它回来?

This in in VS 2015.

这在 VS 2015 中。

回答by Sam Storie

I wrote up a couple of articles about my experience writing Angular 2 applications within Visual Studio:

我写了几篇关于我在 Visual Studio 中编写 Angular 2 应用程序的经验的文章:

https://blog.sstorie.com/0-60-with-angular-2-and-visual-studio-part-2/

https://blog.sstorie.com/0-60-with-angular-2-and-visual-studio-part-2/

In short, you can disable typescript compilation by editing the .csproj file to contain the following:

简而言之,您可以通过编辑 .csproj 文件以包含以下内容来禁用打字稿编译:

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

That should disable all typescript compilation within VS 2015.

这应该禁用 VS 2015 中的所有打字稿编译。

回答by tt9

Sam Storie's answer is a great start and it will stop typescript errors from preventing compilation, but Visual Studio will still report the parsing errors which will prevent the ability to use the built in publishing tools.

Sam Storie 的回答是一个很好的开始,它将阻止打字稿错误阻止编译,但 Visual Studio 仍会报告解析错误,这将阻止使用内置发布工具的能力。

To completely remove error reporting in ts, find all import lines in the csproj that reference typescript and set the Condition property to false, make sure to restart VS afterwards:

要完全去除 ts 中的错误报告,请在 csproj 中找到所有引用 typescript 的导入行并将 Condition 属性设置为 false,确保之后重新启动 VS:

Example:

例子:

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

回答by Saeb Amini

To disable TypeScript compilation altogether for Visual Studio, edit:

要为 Visual Studio 完全禁用 TypeScript 编译,请编辑:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\TypeScript\Microsoft.TypeScript.targets

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\TypeScript\Microsoft.TypeScript.targets

(Your path might be slightly different depending on your OS/VS version, in that case just search for Microsoft.TypeScript.targets)

根据您的 OS/VS 版本,您的路径可能略有不同,在这种情况下,只需搜索Microsoft.TypeScript.targets

And add:

并添加:

<PropertyGroup>
    <TypeScriptCompileBlocked>True</TypeScriptCompileBlocked> 
</PropertyGroup>

This works for .NET Core projects as well.

这也适用于 .NET Core 项目。