csharpier
csharpier copied to clipboard
Formatting doesn't work with multiple project files in a folder
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
- Make sure VS is closed.
- Put two
.csproj
file in the same folder. - 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:
Is there a reason you have two csprojs in the same directory? It seems like that would be very rare.
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.
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.
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.
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.
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
- Run
dotnet-csharpier --version
which should try to invoke the global version and does not care about the projects. - Run
dotnet tool list csharpier -g
and parse the output - 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.