简体   繁体   English

"Visual Studio (2017 & 2019) 忽略 TypeScriptCompileBlocked"

[英]Visual Studio (2017 & 2019) ignoring TypeScriptCompileBlocked

I have been having some problems with Visual Studio compiling Typescript files, this causes a HUGE headache since the compiled .js<\/code> files will be used first instead of using the files generated by SPA Development Server when the project is run.我在 Visual Studio 编译 Typescript 文件时遇到了一些问题,这引起了极大的头痛,因为编译的.js<\/code>文件将首先使用,而不是在项目运行时使用 SPA 开发服务器生成的文件。

I created a React Application ( create-react-app my-app --typescript<\/code> ) and things work just fine until I add a new .tsx<\/code> file.我创建了一个 React 应用程序( create-react-app my-app --typescript<\/code> )并且一切正常,直到我添加一个新的.tsx<\/code>文件。 For some reason VS will always compile the file if added through the Solution Explorer.出于某种原因,如果通过解决方案资源管理器添加,VS 将始终编译该文件。

I made sure that Typescript compiling was disabled in the .csproj<\/code>我确保在.csproj<\/code>中禁用了 Typescript 编译

<PropertyGroup>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    {...}
</PropertyGroup>

There is a setting within the template file itself that is causing the script to compile, there are a couple of ways to handle this, either create a new .tsx template or update the existing one. 模板文件本身中存在一个导致脚本编译的设置,有两种处理方法,即创建新的.tsx模板或更新现有的模板。 The script template lives in 脚本模板位于

C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\ItemTemplates\\AspNetCore\\Web\\Scripts\\1033\\TypeScriptJsxFile

In the tsxFile.vstemplate there is an attribute on the ProjectItem under TemplateContent that tells VS to compile the file, to fix remove the `ItemType="TypeScriptCompile" from the template. 在tsxFile.vstemplate中, TemplateContentProjectItem上有一个属性,该属性告诉VS编译文件,以修复从模板中删除“ ItemType =“ TypeScriptCompile”的问题。 Find the section: 查找部分:

<TemplateContent>
    <ProjectItem SubType="Code" ItemType="TypeScriptCompile" TargetFileName="$fileinputname$.tsx" ReplaceParameters="true">file.tsx</ProjectItem>
</TemplateContent>

And simply remove the entire attribute and save, you will have to edit the file using Administrator permissions if you are updating the template: 只需删除整个属性并保存,如果您要更新模板,则必须使用管理员权限来编辑文件:

<TemplateContent>
    <ProjectItem SubType="Code" TargetFileName="$fileinputname$.tsx" ReplaceParameters="true">file.tsx</ProjectItem>
</TemplateContent>

I did run into some issues when creating a new template, if you have troubles please see this question . 创建新模板时,我确实遇到了一些问题,如果遇到麻烦,请参阅此问题

I used this in my csproj to resolve problem我在我的 csproj 中使用它来解决问题

<PropertyGroup>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptNoEmitOnError>true</TypeScriptNoEmitOnError>
    <TypeScriptNoImplicitReturns>true</TypeScriptNoImplicitReturns>
    <TypeScriptEnableIncrementalMSBuild>false</TypeScriptEnableIncrementalMSBuild>
</PropertyGroup>


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

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