csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Formatting doesn't work with multiple project files in a folder

Open damirarh opened this issue 11 months ago • 6 comments

Environments

  • IDE Version: Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.9.2
  • Extension Version: 1.5.2
  • CSharpier Version: 0.27.3
  • Operating System: Windows 11
  • .csharpierrc Settings: none
  • .editorconfig Settings: none

Log Output

[Debug - 9. 03. 2024 17:19:20] Looking for C:\Users\.config/dotnet-tools.json
[Debug - 9. 03. 2024 17:19:20] Looking for C:\.config/dotnet-tools.json
[Debug - 9. 03. 2024 17:19:20] Unable to find dotnet-tools.json, falling back to running dotnet csharpier --version
[Debug - 9. 03. 2024 17:19:20] Specify which project file to use because this 'C:\Users\damir\Git\Blogposts\20240322-dotnet-extension-method\ExtensionMethod' contains more than one project file.

[Debug - 9. 03. 2024 17:19:20] dotnet csharpier --version output: 
[Debug - 9. 03. 2024 17:19:20] Using  as the version number.
[Warn - 9. 03. 2024 17:19:20] CSharpier was not found so files may not be formatted.
[Debug - 9. 03. 2024 17:19:31] Ensure there is a csharpier process for C:\Users\damir\Git\Blogposts\20240322-dotnet-extension-method\ExtensionMethod

Steps to reproduce

  1. Make sure VS is closed.
  2. Put two .csproj file in the same folder.
  3. Open solution referencing one of the said .csproj files in VS.

Expected behavior

Ideally: CSharpier works.

Alternatively: The warning bar in VS communicates the real reason for failure, which can now only be found in the Output window with debug logs enabled:

Specify which project file to use because this 'C:\Users\damir\Git\Blogposts\20240322-dotnet-extension-method\ExtensionMethod' contains more than one project file.

Actual behavior

The warning bar in VS reports that CSharpier is not installed, which is not true:

image

damirarh avatar Mar 09 '24 16:03 damirarh

Is there a reason you have two csprojs in the same directory? It seems like that would be very rare.

belav avatar Mar 10 '24 03:03 belav

It was not by my choice. Visual Studio created the second one because it detected a conflict in the project file caused by another extension.

damirarh avatar Mar 10 '24 04:03 damirarh

I'm unable to reproduce this and it seems like such an edge case that it isn't worth spending time on. You can install csharpier as a local tool which avoids it having to run dotnet csharpier --version to determine which version is installed.

belav avatar Mar 10 '24 19:03 belav

This happens on any Unity project, those are always created:

Assembly-CSharp-Editor-firstpass.csproj
Assembly-CSharp-Editor.csproj
Assembly-CSharp-firstpass.csproj
Assembly-CSharp.csproj

Trying to run the command in the terminal yields this:

% dotnet csharpier . 
Specify which project file to use because this '[...]' contains more than one project file.

yome avatar Mar 15 '24 15:03 yome

I found a public repo with those https://github.com/XINCGer/Unity3DTraining/tree/master/Minecraft and reproduced the problem now, I'll see what I can figure out.

belav avatar Mar 15 '24 17:03 belav

Dug into this a bit, it seems that "dotnet csharpier --version" is shorthand for "dotnet tool run csharpier --version" and the "dotnet tool run" command is what is upset about the multiple projects. It doesn't have a way to specify a project. My thoughts on potential fixes

  1. Run dotnet-csharpier --version which should try to invoke the global version and does not care about the projects.
  2. Run dotnet tool list csharpier -g and parse the output
  3. Run dotnet csharpier --version at the root of the drive.

I'm leaning towards 2, that won't care about any path issues because the plugins are updated to know where dotnet lives, dotnet-csharpier --version would probably not work well in some cases.

belav avatar Mar 22 '24 20:03 belav