VS 2019: how to disable warning 'Please install the 'Microsoft.TypeScript.MSBuild' NuGet package to enable TypeScript compilation in your project.'

Viewed 2005

How to disable warning 'Please install the 'Microsoft.TypeScript.MSBuild' NuGet package to enable TypeScript compilation in your project.'?

I do not need TS compilation with MSBuild - I do it with custom tools (building webpack bundle, manaually or with devserver).

enter image description here

After changing build action to "Content" warning still exists (details: was "none", this is the only one ts file in the project, solution restart doesn't help; but there are other TS files in other projects and may be they "hooked" somehow the MSBuild warning for all projects with ts files)

enter image description here

2 Answers

It looks like this might be fixed in VS2022, but if you're still on VS2019 the following worked for me:

<PropertyGroup>
    <TypeScriptToolsVersion>4.2</TypeScriptToolsVersion>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>

You'd manually add this to your .csproj file. I had to close and re-open VS afterwards too, but I don't get the error anymore. It also wanted to install TS version 4.2 but it doesn't seem to be compiling with it. Still not a great solution, but it's probably all we've got until Microsoft fixes it:

https://developercommunity.visualstudio.com/t/permanent-warning-please-install-the-microsofttype/1555740

VS 2019: how to disable warning 'Please install the 'Microsoft.TypeScript.MSBuild' NuGet package to enable TypeScript compilation in your project.'

You can use NoWarn msbuild property to suppress this warning.

Solution

Add this in your xxx.csproj file:

<PropertyGroup>
        <NoWarn>xxx(the related waning code like cs0219)</NoWarn>
</PropertyGroup>

================================

Update 1

Since the warning does not have a number, you cannot use NoWarn to suppress it.

Instead, you can use

<WarningLevel>0</WarningLevel>

However, it will suppress all the warnings in your project. For your issue, it is the best way but still has some drawbacks if you want the other warnings.

As a suggestion, you could create a new configuration called Test (Build-->Configuration Manager-->click your project and click New under Configuration drop down box)

, then add these in xxx.csproj file:

<PropertyGroup Condition="'$(Configuration)'=='Test'">
      <WarningLevel>0</WarningLevel>
</PropertyGroup>

You can use the Test Configuration to build your project and it will suppress the warning.

If you want to see the other warnings or handle other warnings, you can switch to Debug or Release mode to build your project.

====================

Update 2

After a deep research, I have reproduced your issue in my side:

enter image description here

Since you do not specify the TypeScript version in MSBuild of VS so that the error occurs.

The cause of it is that you have set the Build Action of the typescript files to TypeScript file. If you set to it, MSBuild will identify them and let MSBuild to use Type Script to build them. Since you do not use TypeScript of MSBuild, so the error happens.

Solution

You can set the Build Action of every typescript file to Content and add custom tool to npm run typescript.

enter image description here

Then restart your project to test again and I am sure that the error will go away.

Related