[Solved] Disabling warnings for a particular Assembly Definition

Is it possible to disable warnings for a particular assembly definition in a project?

I currently have a “ThirdParty” assembly definition with many packages from the internet. Some of them (for example, the unity-ui-extensions) generate a big list of warnings, like “obsolete methods” and “uninitialized fields”. I won’t fix them all, so maybe there’s a way to disable some warnings for a whole assembly?

Something like with the msc.rsp file, but I don’t want to disable warnings for my personal code.

| Solution by @OxDEADFACE:

For ye weary future problem-haver: There’s a pretty easy fix!
This solution is source-controllable, so teams can benefit from just one checked-in change.

  1. Outside of Unity, navigate to your desired subdirectory. I’ll choose Assets/ThirdParty. It doesn’t need to contain an .asmdef, but it may. Note that all child subdirectories will also be squelched, recursively, which is luckily what I want for a “ThirdParty” folder.
  2. Create a new text file named .editorconfig here. (It is normal for this file to never appear in Unity itself, as it starts with a dot.) Open it for edit, and enter [*.cs] for the header line.
  3. In subsequent line(s), you should specify which warnings you’d like to be squelched individually,
    one per line, as follows:
    Say I want to squelch CS0618, a common deprecation warning.
    My next entry in the EditorConfig will be:
dotnet_diagnostic.CS0618.severity = none

And so on.
(You can usually get the warning identifier from the Editor log.)
4. Save the file.
5. In Unity > Project view, find and right-click the icon for your folder, and select Reimport.
6. Profit!

(Do not use this to evade your boss’s strict compiler rules—or do, but you didn’t learn it from me!)

See also: Suppress code analysis warnings - .NET | Microsoft Learn

Tested in Unity 6000000000.

Note: If you don’t want the recursive nature of this fix for whatever reason, you can make your own remedy by utlizing further-nested EditorConfig(s), which you’d configure to override/undo whatever it is the parent config did.

2 Likes

I’m also interested in a solution for this

1 Like

Hi, is there any solution?

1 Like