Search code examples
c#formattingdotnet-format

How to make `dotnet-format` ignoring certain directory?


I have the following lines defined in my .editorconfig file:

# Ignore paths
[Assets/NRSDK/*]

[Assets/VLCUnity/*]

generated_code = true

But they are ineffective, every time I run dotnet-format it still format everything under them. Is it feature broken? What can be done to make it honoured?


Solution

  • For the given .editorconfig content, [Assets/NRSDK/*] and [Assets/VLCUnity/*] are separate section headers. They don't combine. Use [{Assets/NRSDK/*,Assets/VLCUnity/*}] as the section header or duplicate the name/value pairs for both sections.

    It appears that generated_code = true, while used by code analyzers, may not be recognized or honored by dotnet format. (Maybe that should be a feature request.)

    The format subcommand has an --exclude switch. The switch can appear multiple times in the same command line.

    The following should work:

    dotnet format --exclude Assets/NRSDK --exclude Assets/VLCUnity