Skip to content

dotnet format should support custom build configurations #50115

@fschwiet

Description

@fschwiet

Is your feature request related to a problem? Please describe.

I have projects that conditionally include some files based on the build configuration. As a simplified example, suppose my .csproj file contains:

  <ItemGroup Condition="'$(Configuration)' != 'Test'">
    <Compile Remove="**\*Test.cs" />
    <Compile Remove="**\*Tests.cs" />
    <Compile Remove="**\*TestHelper.cs" />
    <Compile Remove="**\TestHelpers\**\*.cs" />
  </ItemGroup>

When I run dotnet format the files matching those patterns are not affected. In particular I do not see unused "using" expressions removed for the *Test.cs files while I will see unused using expressions removed for files not matching the patterns.

Describe the solution you'd like

I am not sure what is possible, but it seems like supporting a --configuration argument should be possible. I would hope to be able to specify the configuration like I would with dotnet build or dotnet test:

dotnet format --configuration Test

This should cause the project to be built and formatted using the specified build configuration.

Additional context

I have further problems with JetBrains rider (I haven't tried visual studio) where after I run dotnet format I cannot build or even rebuild from the IDE. I have to do a "dotnet build --configuration Test" to be able to build from the IDE again. I don't know how Visual Studio behaves. I suspect it has something to do with everyone sharing bin and obj directories. Maybe JetBrains Rider could play nicer with the obj and bin directories if that is the case, I can only speculate. It'd be nice though if dotnet format didn't have that side effect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    untriagedRequest triage from a team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions