OmniSharp formatter does not format C# files - c#

The installed ms-dotnettools.csharp (v1.25.0) extension does not seem to format the C# code : my C# files witch I try to format popups me about missing C# formatter
Visual Studio Code
There is no formatter for 'csharp' files installed.
[Cancel] [Install Formatter...]
I open in the VSCode the entire root folder, containing several projects (C#, Angular etc.), and when opening individual Cs files and try to Shift+Alf+F to format the file, it asks me for the formatter.
I have the following VSCode configuration
Visual Studio Code
Version: 1.67.2 (user setup)
Commit: c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
Date: 2022-05-17T18:15:52.058Z (2 wks ago)
Electron: 17.4.1
Chromium: 98.0.4758.141
Node.js: 16.13.0
V8: 9.8.177.13-electron.0
OS: Windows_NT x64 10.0.19044
also this .net installs
.NET SDK (reflecting any global.json):
Version: 5.0.408
Commit: da985e2a23
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.408\
Host (useful for support):
Version: 5.0.17
Commit: 6a98414363
.NET SDKs installed:
3.1.419 [C:\Program Files\dotnet\sdk]
5.0.407 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
I've checked that, reset it and restarted VSCode, but it has any effect:

You need to either update .Net to 6+ or install a previous version of Omnisharp.
Version 1.25.0 requires .Net 6+. If that's not an option for your environment then you can install a previous version of the Omnisharp extension.
In order to do this, press ctrl/cmd + shift + x to bring the extensions side panel, then click on the configurations wheel and select 'Install another version'.
I tried 1.23.12 and the formatter is working now.
If you run into this issue again you can check the output of the extension to check what could be causing it.
I'm not sure if you found it already, but I'll leave it here in case someone else needs it.

Related

VSCode (or anothers editors) don't recognize sdk dotnet installed with asdf

I have the dotnet installed in my machine with asdf, and even the asdf use the dotnet-install.sh (this is in code of install of dotnet), the DOTNET_ROOT work with the . ~/.asdf/plugins/dotnet-core/set-dotnet-home.zsh set (tested with echo in terminal), and the dotnet work and find the sdk (dotnet --info):
.NET SDK (reflecting any global.json):
Version: 5.0.300
Commit: 2e0c8c940e
Runtime Environment:
OS Name: arch
OS Version:
OS Platform: Linux
RID: arch-x64
Base Path: /home/caneladeouro/.asdf/installs/dotnet-core/5.0.300/sdk/5.0.300/
Host (useful for support):
Version: 5.0.6
Commit: 478b2f8c0e
.NET SDKs installed:
5.0.300 [/home/caneladeouro/.asdf/installs/dotnet-core/5.0.300/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.6 [/home/caneladeouro/.asdf/installs/dotnet-core/5.0.300/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.6 [/home/caneladeouro/.asdf/installs/dotnet-core/5.0.300/shared/Microsoft.NETCore.App]
The Visual Studio Code don't recognized the Sdk of dotnet in folder saying that don't have any .NET Sdk:
It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
https://aka.ms/dotnet-download
The C# VSCode Extension try to find the default dotnet instalation path and don't find, in this case you need to point manually the path to sdk with some environment variables in .NET Documentation. You must define all these variables below in terminal script initialization (such bashrc, zshrc) and show the path to asdf .NET Sdk installation , but can be used to another location, just change the path:
export DOTNET_MSBUILD_SDK_RESOLVER_SDKS_DIR=$(echo $HOME/.asdf/installs/dotnet-core/5.0.300/sdk/*/Sdks)
export DOTNET_MSBUILD_SDK_RESOLVER_SDKS_VER=5.0.300
export DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR=$(echo $HOME/.asdf/installs/dotnet-core/5.0.300)
And yes the Sdk folder is inside the Sdk folder, I confuse too (This take more time to resolve).

Dotnet high memory usage on Mac os

I have installed .Net Core 3.1.300 with asdf-vim and was following csharp tutorial. When i run:
dotnet new console -n BranchesAndLoops -o .
it does use a lot of memory. Is this the norm in C# world? Or have misconfigured something as a dotnet newbie?
❯ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.300
Commit: b2475c1295
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /Users/ogirginc/.asdf/installs/dotnet-core/3.1.300/sdk/3.1.300/
Host (useful for support):
Version: 3.1.4
Commit: 0c2e69caa6
.NET Core SDKs installed:
3.1.300 [/Users/ogirginc/.asdf/installs/dotnet-core/3.1.300/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.4 [/Users/ogirginc/.asdf/installs/dotnet-core/3.1.300/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.4 [/Users/ogirginc/.asdf/installs/dotnet-core/3.1.300/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Even though, I had installed dotnet with asdf-vm, later I had downloaded both the Visual Studio for Mac and Visual Studio Code (installed additional stuff, which I have no idea what they are) to try them rather than tinkering my vimrc.
Probably using both asdf-vm and Visual Studio for Mac caused some internal problems, which made dotnet to get stuck in a hanging status with gradually increasing memory leak.
After uninstalling VS for Mac and VS code, the high memory problem stopped occurring again.

Building an lambda zip file on the commandline in AWS codebuild fails with "the required library libhostfxr.so could not be found"

I am running a command during a AWS CodeBuild in order to build a lambda zip file.
The command is as follows:
dotnet lambda package --framework netcoreapp2.1 -o ../../artifacts/Jobs.zip
Here is the error:
**A fatal error occurred, the required library libhostfxr.so could not be found.
If this is a self-contained application, that library should exist in [/root/.dotnet/tools/.store/amazon.lambda.tools/3.3.1/amazon.lambda.tools/3.3.1/tools/netcoreapp2.1/any/].
If this is a framework-dependent application, install the runtime in the default location [/usr/share/dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location.
Makefile:28: recipe for target 'Jobs/artifacts/Jobs.zip' failed**
Because this is a container I have printed out the dotnet info:
.NET Core SDK (reflecting any global.json):
Version: 2.2.402
Commit: c7f2f96116
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /root/.dotnet/sdk/2.2.402/
Host (useful for support):
Version: 3.1.2
Commit: 916b5cba26
.NET Core SDKs installed:
2.2.402 [/root/.dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.7 [/root/.dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.7 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.7 [/root/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [/root/.dotnet/shared/Microsoft.NETCore.App]
So the project in Visual Studio is targeting .NET Core 2.1
This issue just started about 10 days ago. I was able to go back to an earlier commit, push it to GitHub which kicks of the code build in AWS. This earlier commit, when pushed 2 weeks ago was successful and I did not see this libhostfxr.so error. Basically anything I push now I get the above error.
While researching I found that because I am using a Container, I can use the flag
--self-contained=true and /p:PreserveCompilationContext=true
so that I can bundle all dependencies but that has not worked either.
Not sure what else to try at this point. Does anyone have any ideas? The target framework for these lambdas is .NET core 2.1.
After more research I found the solution here. https://github.com/aws/aws-codebuild-docker-images/issues/321
I need to set the DOTNET_ROOT in my yml file.

Cannot install dotnet-ef tool on Windows 10

I'm trying to install the dotnet-ef tool via the dotnet-cli.
The command that I enter: dotnet tool install --global dotnet-ef
I gives me the following error:
The tool package could not be restored.
Tool 'dotnet-ef' failed to install. This failure may have been caused by:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
I'm using dotnet 3.0, I believe I didn't have this problem on MacOS, I'm now trying to execute the same command on my Windows 10 machine and it gives me that error.
Some info using dotnet --info command:
.NET Core SDK (reflecting any global.json):
Version: 3.0.100
Commit: 04339c3a26
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100\
Host (useful for support):
Version: 3.0.0
Commit: 7d57652f33
.NET Core SDKs installed:
3.0.100 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
I got it working by adding the --version flag and specifying the version to 3.0.0.
The command that I used:
dotnet tool install --global dotnet-ef --version 3.0.0
dotnet tool install -g dotnet-ef --ignore-failed-sources worked for me. Thanks to Anas-Alhariri
Source
I had the same issue on Mac OS recently.
It was related to the fact that we use our own NuGet feed (packageSources section).
So, I fixed that by removing the custom NuGet feed from NuGet.config file for a while.
If everything else failed then you should check in your Visual Studio the next route: Tools > NuGet Package Manager > Package Manager Settings > Nuget Package Manager > Package Sources.
There you should have nuget.org, if not and you only have Microsoft Visual Studio Offline Packages, well that is the problem. Next you need to add the package resource nuget.org like this:
Once you click Ok you can go back to your terminal and install dotnet-ef with no problem.
I got this error message, but when I closely inspected all the errors I also had:
Response status code does not indicate success: 407 (Proxy Authorization Required).
Turning off the proxy while running the command fixed the issue.
I got this error when I tried to run the command from the Package Manager Console instead of a Powershell command window.
For some of reasons you can try to delete directory C:\Program Files\dotnet\sdk-manifests it will make you can download it.
.net 6
ref : https://github.com/dotnet/sdk/issues/23435

VSCode Unity OmniSharp .NETFramework not found

I get this message in the output of VSCode
[fail]: OmniSharp.MSBuild.ProjectLoader
The reference assemblies for framework ".NETFramework,Version=v4.7.1" were not found.
To resolve this, install the SDK or Targeting Pack for this framework version
or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the
Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
this is what my dotnet output looks like
~ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.2.106
Commit: aa79b139a8
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.14
OS Platform: Darwin
RID: osx.10.14-x64
Base Path: /usr/local/share/dotnet/sdk/2.2.106/
Host (useful for support):
Version: 2.2.4
Commit: f95848e524
.NET Core SDKs installed:
2.2.106 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
With this error I can't get any IDE features for C# in VSCode.
Close VS Code.
Download and install Microsoft .NET Framework 4.7.1.
Download and install Microsoft's .NET Framework SDK any version with start 4.X
In VS Code, open Assembly_CSharp.csproj file and change TargetFrameworkVersion to what you installed .NET Framework SDK version.
You should have both .NET framework and targeting sdk installed for a particular version.
This is a temporary solution because targetFrameworkVersion always changes to unity defaults when you close the editor
Install latest stable Mono Version should fix the issue for this one, if anyone faces a similar issue.
Or try a different one until it is resolved, might be some mono versions preventing this.
The following worked for me (Unity 2022.3.3f1):
Install C# VS Code plugin
Download and install 4.7.1 Developer Pack (you will need to scroll past .NET Core to .NET Framework) (this version number may be different, but it will appear in the OUTPUT tab of VSCode as the version of C# you are using with unity.)
The file will look like ndp471-devpack-enu.exe
Download and install .NET sdk for Visual Studio (same download as this page). This will add dotnet to your PATH and get VSCode to recognize it. Omnisharp/Intellisense did not work for me without this step.
The file will look like dotnet-sdk-6.0.300-win-x64.exe
In Unity, Go to Edit > Preferences > External Tools and ensure Visual Studio Code is the External Script Editor. Press Regenerate project files
Restart PC
You shouldn't need to change settings.json or anything else

Categories