0

I'm using Visual Studio Code to write my scripts in C# for Unity. Unfortunately I have redundant warnings that resolving cause my project to broke. Mostly I am talking about:

  • IDE0051 Remove unused private member - for functions Start() & Update()
  • IDE0044 Make field readonly - I'm using [SerializeFields] for my private fields, which changing them to readonly makes them not visible in Inspector.

Using #pragma warning disable works, but I'm looking for solution to my whole project. Main .NET Microsoft site for these warnings (here, and here) suggests that I need to set its severity to none in configuration file. The problem is I don't know where configuration file for VS Code projects is. So I'm stuck.

starball
  • 20,030
  • 7
  • 43
  • 238
daveekh
  • 5
  • 2
  • 1
    well the configuration file as is described in your provided urls, is just any file with the ending ".editorconfig" in can be placed in any root (or directly at) location of your project files - maybe this helps: https://stackoverflow.com/questions/47357322 – Rand Random Aug 03 '23 at 14:02
  • 1
    Thank you all for responses. @RandRandom Indeed, I needed to install Editor Config extension first and then create an .editorconfig file. Now it works like a charm. – daveekh Aug 04 '23 at 13:32
  • @starball I installed the newly Unity extension but it didn't get rid of the warnings. I acknowledge the fact that above solution is only a temporary one, so [I raised a ticket also](https://github.com/microsoft/vscode-dotnettools/issues/322) and I will track if the problem is resolved. – daveekh Aug 04 '23 at 13:32
  • not sure if related: https://stackoverflow.com/q/76850403/11107541 – starball Aug 07 '23 at 09:33

1 Answers1

3

There were recent changes to support for Unity in VS Code. See https://devblogs.microsoft.com/visualstudio/announcing-the-unity-extension-for-visual-studio-code/. The root problem with incorrect errors seems to have been resolved by updating the C# Dev Kit extension to the pre-release 0.4.2 version, verified by updating and deleting the .editorconfig file to check if it works (source).


If you want to disable warnings/hints, you might be able to do it with an editorconfig like this (source):

[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none
dotnet_analyzer_diagnostic.category-CodeQuality.severity = none

Or alternatively, if you want to just hide the squiggly underlines, see https://stackoverflow.com/a/74934214/11107541.

starball
  • 20,030
  • 7
  • 43
  • 238