How do I make VS Code treat a specific warning as an error?

In VS I set the FS0025 warning (Incomplete pattern matches on this expression) to be treated as an error so I can’t compile the code if I’ve missed something. (I can’t remember how I did it in VS.)

However, I can’t figure out how to make VS Code do the same thing.

I’ve searched the “File → Preferences → Settings” for ‘error’ and ‘warning’ but can’t find anything.
I’ve looked at various articles and references on the web but can’t find anything which matches (pardon the pun) my requirements, the answers are usually for either C# or VS but not F# and VS Code.

I’d like this setting to be automatically applied to all of my previous, current and future F# projects but not any other type of project.

Is it possible to do this without having to (remember to) add <WarningsAsErrors>FS0025</WarningsAsErrors> into each fsproj file?

Note: I don’t really want to go ‘messing around with the compiler’ if I don’t have to as I’m not confident enough to do it and remember that I’ve done it and back-out the changes if it causes problems down the road.

1 Like

Right now, you can’t configure it.

However, there is a draft PR to allow the user to add MSBuild properties via VSCode config which is probably what you need for your use case.

You can also put <WarningsAsErrors>FS0025</WarningsAsErrors> into at the root of your projects directory.

Thanks for your reply MangelMaxime.
I’ve read the PR but, unfortunately, most of it is way over my head and I don’t understand it.
Hopefully it will do what I need though.

Thanks for your reply Martin521 (and welcome to the community by the way).

Unfortunately I don’t know what is, or where it is, or what it does (I’ve looked and didn’t find anything like that).

I think I would prefer to add that line into the fsproj file for each project, if I had to do anything like that, but, as mentioned in my original post, I would prefer not to have to remember to do it for every project.

Hopefully something will come from the PR as mentioned above.


That file you need to create yourself. It is one of the special msbuild files that do magic stuff. You can read about it here:
Don’t concern yourself with msbuild yet through. Most of my fellow developers with near a decade worth of experience in .net do not know how it works and what it can do.

For you, just create that file in the root of your project next to the solution file (.sln) and add the property in the file.


1 Like

Directory.Build.props work hierachical and quite practical. if you have multiple different solutions in one repo and they also may have different net versions. Then you can enable or disable features through that file.

<root of repo>
 |-<sub directory solution 1>
   |- Directory.Build.props
 |-<sub directory solution 2>
   |- Directory.Build.props

content of props file in sub directory could be this and additional options

  <Import Project="../Directory.Build.props" />

Thanks for the extra information ajeckmans and Rico Saupe.

I’ll have to read more about this Directory.Build.props thing and give it a try at some point.