format icon indicating copy to clipboard operation
format copied to clipboard

Question: Can i format all .csproj files?

Open sommmen opened this issue 3 years ago • 4 comments

Hiya,

I'm looking for something that can format all .csproj files - is that something that this tool can do, and if so - what would the command look like?

sommmen avatar Sep 13 '21 16:09 sommmen

Hi @sommmen, Unfortunately, we do not currently support formatting .csproj files. We have an open feature request (https://github.com/dotnet/format/issues/647) to add this support. What type of formatting options are you expecting (tabs vs. spaces, charset, consistent indentation, ...)?

JoeRobich avatar Sep 13 '21 16:09 JoeRobich

@JoeRobich Hiya - thanks for answering my question.

The issue i'm having right now is that i used PowerShell to bulk edit .csproj files to make sure the RootNameSpaceName and AssemblyName elements were consistently prefixed with a shortname of the company, eg:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    
  <RootNamespace>CMP.AuthApi</RootNamespace><AssemblyName>CMP.AuthApi</AssemblyName></PropertyGroup>

</Project>

As you can see from the resulting xml - that doesn't look too good. Also it means that i get a lot of changed files. I gave up on getting the output to format correctly in PowerShell so i moved to look for some kind of tool.

In a more broader sense, for me, i'd like the format tool to format the .csproj the same way visual studio does to remain consistent. I gues in my mind the identation is the most important.

EDIT: This SO describes my issue somewhat https://stackoverflow.com/q/58245356/4122889

sommmen avatar Sep 13 '21 16:09 sommmen

Please include XML, XSD files to this request

We have this configuration in .editorconfig but its not auto formatted [*.{xml,xsd}] max_line_length = off end_of_line = lf indent_style = space charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true indent_size = 2

chandramouleswaran avatar Nov 04 '21 23:11 chandramouleswaran

@JoeRobich It is silly but the IDE of a coworker of mine inserts package references like so: <PackageReference Include="MassTransit" Version="8.0.7" /> and my IDE (vs) does it like so: <PackageReference Include="MassTransit" Version="8.0.7"/> If you notice there is a whitespace after the last attribute, it always causes conflict when merging. Rider has the option to control this whitespace and can be added to .editorconfig https://www.jetbrains.com/help/resharper/EditorConfig_XML_XmlCodeStylePageSchema.html#resharper_xml_space_after_last_pi_attribute but only rider respects it, vs & vs code doesn't. So it would be great if dotnet format could enforce that.

Abdulrhman5 avatar Apr 19 '23 10:04 Abdulrhman5