Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScriptCompileBlocked Ignored by Visual Studio 2019

I have a problem with my TypeScript project and VS19: enter image description here

I have added this to the .csproj to prevent VS to show "errors" in error list:

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

The .csproj has no <ItemGroup> that includes any ts or tsx files.

I use webpack, tsconfig, eslint, etc. to handle all FE stuff. Thats the reason I dont want to have VS19 help on this :).

I need this to work because my colleges gets this to and seeing 1000+ "errors" is really annoying.

I have found some solutions to change files that are on your computer locally. But I dont want that, I need a solution that will work as soon as you pull the project from 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"]
}

Edit: Ok so I added this:

<ItemGroup>
    <None Remove="Web\**\*.tsx" />
    <None Remove="Web\**\*.ts" />
    <None Remove="Web\**\*.js" />
    <None Remove="Web\**\*.html" />
    <Content Remove="Web\*.json" />
</ItemGroup>

obviously VS19 dont compile the files now, but there must be a better solution than this. vs19 cant be this stupid.. :)

like image 279
J4v4Scr1pt Avatar asked Oct 28 '25 12:10

J4v4Scr1pt


1 Answers

TypeScriptCompileBlocked usually works fine.

The main reason why files still appear in my experience is because I have many projects in my solution and one or more don't have TypeScriptCompileBlocked set to True.

I think when MSBuild runs C:\Program Files (x86)\Microsoft SDKs\TypeScript\4.1\build\Microsoft.TypeScript.targets for any project without TypeScriptCompileBlocked it looks like it triggers tsc compiler with --listFilesOnly flag to return list of files covered by you tsconfig.json. Like this (a copy from my verbose logs):

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)

In result it usually gets all the ts files anyway and since TypeScriptCompileBlocked is not set to True for a project VsTsc builds all of them.

When I have this I usually run MSBuild (or build in VS 2019) with Verbose logs enabled and search for TypeScriptCompileBlocked = false, somewhere around you may find TypeScriptProjectDir property which may help you to identify what project is it.

Another solution I often use is to have a global .targets file which is imported in every project in my solution. I can use it to set TypeScriptCompileBlocked and other global things I want in one place.

like image 164
Yes Alex Avatar answered Oct 30 '25 01:10

Yes Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!