Closed evertonandrade closed 9 months ago
I believe the problem has to do with PATH
, and the extension not being able to run the dotnet csharpier --version
command to determine which version of CSharpier is being used. I have an open issue to try to add better support for this #893
I'm not familiar with Linux, so I don't know if the workaround for macOS from that issue also applies.
You also may be able to use this setting I added for testing the extensions as a workaround. It will keep the application running from that location but I believe that is only a problem with windows.
"csharpier.dev.customPath": "[PathToFolderContainingDotnetCSharpier]"
Hi @belav
this solution didn't work for me =/
however, via cli it worked
It's a problem with the extension to find the global csharpier because with a local installation it also works
Hey @evertonandrade I have ubuntu set up now and am digging into this.
If you run which dotnet
in vscode, what is the result?
And by chance do you have any of the following set?
"dotnet.dotnetPath": "",
"dotnetAcquisitionExtension.existingDotnetPath": [ "" ],
"omnisharp.sdkPath": "",
@belav
running which dotnet
in vscode I have the output /usr/bin/dotnet
:
in my settings.json (ctrl + shift + p > Preferences: Open User Settings (JSON), i don't have:
"dotnet.dotnetPath": "",
"dotnetAcquisitionExtension.existingDotnetPath": [ "" ],
"omnisharp.sdkPath": ""
@evertonandrade I have these changes mostly done, I just want to do some more testing. I was going to install arch linux because I believe it may handle PATH a bit differently than ubuntu, but it didn't seem like a straightforward install.
I'm hoping the new beta will find dotnet automatically for you but if not the extension now supports setting dotnet.dotnetPath
or omnisharp.dotNetCliPaths
.
If you have a chance to try it out let me know if it is working.
@belav , I've been investigating and found the problem.
For some reason, process.env.PATH when called from running a vscode extension does not show me the full PATH of my system. I created a small test playground extension to verify this. The result was:
However, in another testing playground for nodejs I have the complete result:
Another test I did was run vscode as root user
sudo code Dev/playgrounds/vscode-extension-playground --no-sandbox --user-data-dir="~/.vscode-root"
This way I was able to access the complete PATH of the system
I still have no idea why this behavior happens. until recently the extension works well on my Arch Linux.
@evertonandrade Did the c# extension continue to work? I pulled in some code from that, and they don't appear to be doing anything out of the ordinary when trying to locate dotnet
on the PATH.
Someone had mentioned that running sh -c "dotnet"
may work better with PATH, so I included that logic in the latest version of the extension. It also shows an error message letting the user know why it can't format anything and contains logs that should help track down any PATH issues.
@belav
The problem is not dotnet. The C# (Microsoft) extension is working fine. The problem is the installed tools that can only be called when they are in the PATH.
In my .zshrc file I add export PATH="$PATH:$HOME/.dotnet/tools/"
to the end, and the tool works perfectly via the cli, however, in the vscode context it was not possible to access it because in the PATH is not available (unless I run as root user).
Environments
Log Output ["ERROR" - 7:41:38 PM] CSharpier was not found so files may not be formatted. ["INFO" - 7:41:38 PM] 1 ["INFO" - 7:41:40 PM] Formatting started for /home/everton/Dev/playgrounds/CSharpPlayground/Program.cs. ["DEBUG" - 7:41:40 PM] /home/everton/.vscode/extensions/csharpier.csharpier-vscode-1.5.2/build ["DEBUG" - 7:41:40 PM] /home/everton/.vscode/extensions/csharpier.csharpier-vscode-1.5.2/build ["DEBUG" - 7:41:40 PM] Ensure there is a csharpier process for /home/everton/Dev/playgrounds/CSharpPlayground ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/playgrounds/CSharpPlayground/.csproj ["DEBUG" - 7:41:40 PM] Looking at /home/everton/Dev/playgrounds/CSharpPlayground/CSharpPlayground.csproj ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/playgrounds/CSharpPlayground/.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/playgrounds/.csproj ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/playgrounds/.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/.csproj ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Looking for /home/everton/.csproj ["DEBUG" - 7:41:40 PM] Looking for /home/everton/.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Looking for /home/.csproj ["DEBUG" - 7:41:40 PM] Looking for /home/.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Looking for //.csproj ["DEBUG" - 7:41:40 PM] Looking for /.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Unable to find dotnet-tools.json, falling back to running dotnet csharpier --version ["DEBUG" - 7:41:41 PM] dotnet csharpier --version failed with Could not execute because the specified command or file was not found. Possible reasons for this include:
["ERROR" - 7:41:41 PM] CSharpier was not found so files may not be formatted. ["INFO" - 7:41:41 PM] 1 ["DEBUG" - 7:41:41 PM] returning NullCSharpierProcess because there was no csharpierProcessesByVersion for ["DEBUG" - 7:41:41 PM] Skipping formatting because this is a NullCSharpierProcess. This generally indicates there was a problem starting the CSharpier process ["INFO" - 7:41:41 PM] Formatted in 860.4347350001335ms ["DEBUG" - 7:41:41 PM] result is empty
Steps to reproduce
Expected behavior It was expected that with the tool installed globally, formatting would work, but this does not happen. The extension only works with local installation
Actual behavior With global installation it is not possible to use the extension, even passing the correct path to dotnet-csharpier