Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.cs code files in Shared Projects are not formatted #945

Open
samtrion opened this issue Aug 30, 2023 · 5 comments
Open

.cs code files in Shared Projects are not formatted #945

samtrion opened this issue Aug 30, 2023 · 5 comments
Labels
area:msbuild type:enhancement New feature or request

Comments

@samtrion
Copy link
Contributor

If you use Shared Projects .shproj, the contents are not formatted here. Although the code actually belongs to the consuming .csproj projects.

@belav
Copy link
Owner

belav commented Aug 31, 2023

Do you have an example of your setup? I am assuming the projects are using CSharpier.MSBuild. The dotnet tool just works on directory contents and has been working with the CSharpier VS plugin, which uses a shared project.

@samtrion
Copy link
Contributor Author

@belav
Copy link
Owner

belav commented Sep 1, 2023

Can you provide more than just a link? How do I reproduce the problem?

@samtrion
Copy link
Contributor Author

samtrion commented Sep 5, 2023

I have created a sample repository with the error image. - https://github.com/samtrion/bug-csharpier-945

By way of explanation, I use a Directory.Packages.props file in parallel with the .sln file to manage packages. Through this file I inject CSharpier into all projects.

The code inside the .csproj projects is formatted correctly, but the code inside the .shproj or .projitems is not formatted. There is a standard import between the projects.

The same error pattern can be observed via a link reference to a file.

<ItemGroup>
  <Compile Include="..\Test.Shared\ExtraLongMethodBody.cs" Link="ExtraLongMethodBody.cs" />
</ItemGroup>

Also in this case the file ExtraLongMethodBody.cs is not formatted.

@belav
Copy link
Owner

belav commented Sep 8, 2023

Thanks, I can see the problem now, but there isn't an easy fix.

The way CSharpier.MSBuild currently works is by just running dotnet csharpier against the project directory. It doesn't currently understand anything about the project. It also will not format a file if it was included from outside of the project directory and will format files that were excluded from the project.

dotnet format does this to determine formattable files - https://github.com/dotnet/format/blob/452f6263277533da0af2b557003256d98fbecc27/src/CodeFormatter.cs#L171

There may be some other way to do this in the context of msbuild, but my googling hasn't turned up anything yet.

@belav belav added area:msbuild type:enhancement New feature or request labels Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:msbuild type:enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants