我已将此添加到 .csproj 以防止 VS 在错误列表中显示“错误”:
<PropertyGroup>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
.csproj 没有 <ItemGroup>
包括任何 ts 或 tsx 文件。
我使用 webpack、tsconfig、eslint 等来处理所有 FE 的东西。 这就是我不想让 VS19 帮助解决这个问题的原因:)。
我需要它来工作,因为我的大学已经做到了,看到 1000 多个“错误”真的很烦人。
我找到了一些更改本地计算机上文件的解决方案。但我不想要那样,我需要一个只要你从 git 中拉出项目就可以工作的解决方案。
.tsconfig:
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"Colors": ["classes/Colors"],
"Api": ["assets/Api"],
"Components/*": ["src/app/sharedComponents/*"],
"Classes/*": ["classes/*"],
"RegExMatchers": ["assets/RegexMatchers"]
},
"types": ["node"],
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": false,
"jsx": "react-jsx",
"declaration": true,
"typeRoots": ["./src/@types", "../node_modules/@types"]
},
"include": ["./src/**/*", "./@types/", "./assets/"],
"exclude": ["node_modules"]
}
编辑: 好的,所以我添加了这个:
<ItemGroup>
<None Remove="Web\**\*.tsx" />
<None Remove="Web\**\*.ts" />
<None Remove="Web\**\*.js" />
<None Remove="Web\**\*.html" />
<Content Remove="Web\*.json" />
</ItemGroup>
显然 VS19 现在不编译文件,但必须有比这更好的解决方案。 vs19 不可能这么蠢.. :)
最佳答案
TypeScriptCompileBlocked
通常工作正常。
文件仍然出现在我的经验中的主要原因是因为我的解决方案中有很多项目,并且一个或多个项目没有将 TypeScriptCompileBlocked
设置为 True
。
我认为当 MSBuild 为任何没有 TypeScriptCompileBlocked 的项目运行 C:\Program Files (x86)\Microsoft SDKs\TypeScript\4.1\build\Microsoft.TypeScript.targets 时,它看起来会触发 tsc
编译器带有 --listFilesOnly
标志以返回您覆盖的文件列表 tsconfig.json
。像这样(我的详细日志的副本):
45> C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\NodeJs\node.exe "C:\Program Files (x86)\Microsoft SDKs\TypeScript\4.1\tsc.js" --project "C:***\tsconfig.json" --listEmittedFiles --locale en-US --listFilesOnly (TaskId:432)
结果,它通常无论如何都会获取所有 ts 文件,因为 TypeScriptCompileBlocked
没有为项目设置为 True VsTsc 构建所有这些文件。
当我有这个时,我通常在启用详细日志的情况下运行 MSBuild(或在 VS 2019 中构建)并搜索 TypeScriptCompileBlocked = false
,您可能会在周围的某个地方找到 TypeScriptProjectDir
属性这可能会帮助您确定它是什么项目。
我经常使用的另一个解决方案是在我的解决方案的每个项目中导入一个全局 .targets
文件。我可以用它在一个地方设置 TypeScriptCompileBlocked
和我想要的其他全局内容。
关于Visual Studio 2019 忽略了 TypeScriptCompileBlocked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68268488/