VSCode autocompletion for C# on Ubuntu - c#

I am trying to setup an environment to code a Unity projet on my Ubuntu 20.04 computer.
I want to use VSCode to write my C# code. As required, I installed .NET SDK 5.0.201.
So, I tried to run some code but VSCode does not seem to recognize my .NET installation. Every time I open VSCode, I get the following message :
The .NET Core SDK cannot be located. .NET Core debugging will not be enabled. Make sure the .NET Core SDK is installed and is on the path.
And (the main problem), I do not have auto-completion on my C# code.
I don't really understand what is the problem here. .NET is correctly recognized in my terminal (both ubuntu terminal and terminal inside VSCode)
>> dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.201
Commit: a09bd5c86c
Runtime Environment:
OS Name: ubuntu
OS Version: 20.04
OS Platform: Linux
RID: ubuntu.20.04-x64
Base Path: /snap/dotnet-sdk/116/sdk/5.0.201/
Host (useful for support):
Version: 5.0.4
Commit: f27d337295
.NET SDKs installed:
5.0.201 [/snap/dotnet-sdk/116/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.4 [/snap/dotnet-sdk/116/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.4 [/snap/dotnet-sdk/116/shared/Microsoft.NETCore.App]
What am I missing here ?
EDIT
The C# extension can't load either and give me the following message :
The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks
[warn]: OmniSharp.MSBuild.ProjectManager
Failed to load project file '/path/to/my/project/Assembly-CSharp.csproj'.
/path/to/my/project/Assembly-CSharp.csproj
/home/me/.vscode/extensions/ms-dotnettools.csharp-1.23.9/.omnisharp/1.37.6/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1180,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

I finally found the answer !
In VSCode setting, I configured
"omnisharp.useGlobalMono": "always"
Instead of
"omnisharp.useGlobalMono": "auto"
And it did the trick

Related

Is it possible to run .NET Framework WPF application with .NET 7? (Windows 10)

I'm working on a WPF project that targets .NET Framework 4.8
1/
Now I'm researching about running that application with .NET 7 but is it possible to do that?
For example, I tried dotnet wpf.exe but it shown some errors
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Users\admin\Documents\Debug\'.
Failed to run as a self-contained app.
- The application was run as a self-contained app because 'C:\Users\admin\Documents\Debug\wpf.runtimeconfig.json' was not found.
- If this should be a framework-dependent app, add the 'C:\Users\admin\Documents\Debug\wpf.runtimeconfig.json' file and specify the appropriate framework.
This is some info about the environment (from dotnet --info)
I've installed a new Windows 10 22H2 so I think .NET Framework 4.8 is included
.NET SDK:
Version: 7.0.101
Commit: bb24aafa11
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.101\
Host:
Version: 7.0.1
Architecture: x64
Commit: 97203d38ba
.NET SDKs installed:
7.0.101 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
2/
If the above is impossible, is there a way to build the .NET Framework project so it can run with .NET 7 without changing (migrating) the current project structure? (Something like I can continue working on .NET Framework project as before then use a specific dotnet command to build it to .NET 7 executable. Assuming all packages are compatible with .NET 7)
Now I'm researching about running that application with .NET 7 but is it possible to do that?
No. A WPF application that targets the .NET Framework cannot run on the .NET Core/5/6/7 runtime.
You will either have to migrate your application to .NET 7 or stick with running it on the old .NET Framework runtime.
You may target multiple frameworks using an SDK-style project but that's another story. If you want to take advantage of the features available in .NET 7, you will have to migrate and this includes the project file as well. You can still be compatible with .NET Framework if you want though.
But there is no option of doing nothing with the code base and simply run the .NET Framework app as-is on .NET Core or later versions.
The migration itself doesn't necessarily have to be that tricky depending on your code base. Please refer to the link above for more information.

How to fix "No .NET SDKs were found." error--VSCode

I'm trying to setup a backend on my local computer I have installed the v6 dotnet everything is installed but when i run dotnet run
I get this error
The command could not be loaded, possibly because:
* You intended to execute a .NET application:
The application 'run' does not exist.
* You intended to execute a .NET SDK command:
No .NET SDKs were found.
Download a .NET SDK:
https://aka.ms/dotnet-download
Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found
dotnet --info
PS C:\Users\Az\bazaar-online\Server\Src\BazaarOnline.API> dotnet --info
global.json file:
Not found
Host:
Version: 6.0.7
Architecture: x86
Commit: 0ec02c8c96
.NET SDKs installed:
No SDKs were found.
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Download .NET:
https://aka.ms/dotnet-download
Learn about .NET Runtimes and SDKs:
https://aka.ms/dotnet/runtimes-sdk-info
I searched a lot but i didn't find anything useful.
reinstalled everything tried v3 but didn't fix anything
I have installed these files.
dotnet-hosting-6.0.7-win
dotnet-runtime-6.0.7-win-x64
dotnet-sdk-6.0.302-win-x64
Ok This fixed the problem for me
I went to the C:\Program Files (x86)\dotnet
and deleted everthing in the folder
and than vscode recognized the dotnet sdk.
The command could not be loaded, possibly because:
You intended to execute a .NET application:
The application 'myapp.dll' does not exist.
You intended to execute a .NET SDK command:
No .NET SDKs were found.
Download a .NET SDK:
https://aka.ms/dotnet-download
Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found
use this commands
1.sudo apt remove dotnet*
2.sudo apt remove aspnetcore*
3.sudo rm /etc/apt/sources.list.d/microsoft-prod.list
4.sudo apt update
5.sudo apt install dotnet-sdk-6.0
I just had this same issue when I wanted to install a new template dotnet new -i "Falco.Template::*". Simply reinstalling the dotnet 6 SDK solved it for me.

Visual Studio 2022 Mac M1 .NET 6, Could not load file or assembly 'Microsoft.Build

I am having an issue with .NET 6 on Visual Studio 2022 Mac M1 chip. What happens is when I want to build or clean my WebApi project I get the following error.
The operation failed due to an internal error: Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. An attempt was made to load a program with an incorrect format.
This is what I have for dotnet --info command
.NET SDK (reflecting any global.json):
Version: 6.0.200
Commit: 4c30de7899
Runtime Environment:
OS Name: Mac OS X
OS Version: 12.2
OS Platform: Darwin
RID: osx.12-x64
Base Path: /usr/local/share/dotnet/x64/sdk/6.0.200/
Host (useful for support):
Version: 6.0.2
Commit: 839cdfb0ec
.NET SDKs installed:
3.1.416 [/usr/local/share/dotnet/x64/sdk]
5.0.405 [/usr/local/share/dotnet/x64/sdk]
6.0.102 [/usr/local/share/dotnet/x64/sdk]
6.0.200 [/usr/local/share/dotnet/x64/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.22 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.14 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.2 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.22 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.14 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.2 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]`
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
I have tried many things but none of them has worked. I would appricate any help!
I change the setting the SDK location from
/usr/local/share/dotnet/x64/dotnet
to
/usr/local/share/dotnet/dotnet
I was facing the same issue and I was able to make it work. (also Mac M1 chip)
But I did several actions, I'm not sure which one was responsible for fixing it.
I think my problem was related to having both "Visual Studio 2019 for Mac" and "Visual Studio 2022 Preview for Mac" installed.
I've uninstalled both.
Then I removed all SDK files cleaning both:
/usr/local/share/dotnet/x64
and
/usr/local/share/dotnet/
(YMMV here, I used this article to discover those paths)
Then I installed only the "Visual Studio 2022 Preview for Mac", with its net6.0 sdk.
Opened my solution and it didn't work (because my solution was net5.0).
Then I installed the old "Visual Studio 2019 for Mac" (to get the x64 net5.0 sdk installed).
And when I opened the solution in the new "VS 2022 Preview", it now worked.
At a given moment, I updated the .NET Core SDK location on Preferences:
To /usr/local/share/dotnet/dotnet
(which I think is the location for the net6)
I know my answer is not precise, but I count on the community help to test these steps and then I can edit it here. :)

Can't create a web app with .NET Core 3.1 on Visual Studio (Mac)

I'm brand new to Visual Studio IDE and learning C#. I'm following Microsoft's Web apps/Razor Pages Tutorial and i've already installed Visual Studio and dotnet 3.1
I'm attempting to start a new project but for some reason I can't seem to click the "create" button. Nothing happens. I am able to create a project with 3.0 but this causes some versioning issues with eventual packages that I'll be installing.
Here's information on my dotnet versioning:
dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.100
Commit: cd82f021f4
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /usr/local/share/dotnet/sdk/3.1.100/
Host (useful for support):
Version: 3.1.0
Commit: 65f04fb6db
.NET Core SDKs installed:
3.0.101 [/usr/local/share/dotnet/sdk]
3.1.100 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
And here is where the project creation is halted:
Visual Studio Mac will only support .net core 3.1 with the new version 8.4.
You can switch the update channel to preview and do the updates. After installing the preview updates the creation of projects with .net core 3.1 works for me.
What I've done as a workaround is create the project as dotnet core 3.0. And then simply edit the csproj files to target 3.1:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

"Unable to create directory "/Debug/". Access to the path "/Debug/" is denied." when opening Unity3D project with Visual Studio Code on Ubuntu

I moved to Ubuntu 19.04 from Windows 10, and I have some Unity projects from the past to work on. I installed VS Code from the Microsoft site, the C# and Unity Debugger extensions, .NET SDK 2.2, latest Mono (6.0.0.319) and Unity 2019.2.0f1. When I try to open the project, the OmniSharp log says:
[warn]: OmniSharp.MSBuild.ProjectLoader Unable to create directory "/Debug/". Access to the path "/Debug/" is denied.
and some other errors led by this, which cause the .csproj file not to load.
First, I've googled the problem, but found only one suiting thread saying I need to reinstall msbuild. But there isn't any msbuild package on APT, so I went to MSBuild's GitHub and it said msbuild wasn't shipping separately from .NET SDK.
Then I uninstalled Mono, but VSC said me I don't have the ".NET Framework 4.7.1", so I installed Mono again.
Later I reinstalled both .NET SDK and VS Code, but the issue seemed to remain.
This is my dotnet --info if it can help solving:
Пакет SDK для .NET Core (отражающий любой global.json):
Version: 2.2.401
Commit: 729b316c13
Среда выполнения:
OS Name: ubuntu
OS Version: 19.04
OS Platform: Linux
RID: ubuntu.19.04-x64
Base Path: /usr/share/dotnet/sdk/2.2.401/
Host (useful for support):
Version: 2.2.6
Commit: 7dac9b1b51
.NET Core SDKs installed:
2.2.401 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
The OmniSharp log itself (starting from the warn):
[info]: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location '/home/alt3r3d/UnityProjects/some random test' on host 14700.
[warn]: OmniSharp.MSBuild.ProjectLoader
Unable to create directory "/Debug/". Access to the path "/Debug/" is denied.
[warn]: OmniSharp.MSBuild.ProjectLoader
Could not write state file "/Debug/Assembly-CSharp.csprojAssemblyReference.cache". Could not find a part of the path "/Debug/Assembly-CSharp.csprojAssemblyReference.cache".
[fail]: OmniSharp.MSBuild.ProjectLoader
Could not write lines to file "/Debug/Assembly-CSharp.csproj.CoreCompileInputs.cache". Could not find a part of the path "/Debug/Assembly-CSharp.csproj.CoreCompileInputs.cache".
[warn]: OmniSharp.MSBuild.ProjectManager
Failed to load project file '/home/alt3r3d/UnityProjects/some random test/Assembly-CSharp.csproj'.
/home/alt3r3d/UnityProjects/some random test/Assembly-CSharp.csproj
/home/alt3r3d/.vscode/extensions/ms-vscode.csharp-1.21.0/.omnisharp/1.34.0/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1144,5): Error: Unable to create directory "/Debug/". Access to the path "/Debug/" is denied.
/home/alt3r3d/.vscode/extensions/ms-vscode.csharp-1.21.0/.omnisharp/1.34.0/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(2130,5): Error: Could not write state file "/Debug/Assembly-CSharp.csprojAssemblyReference.cache". Could not find a part of the path "/Debug/Assembly-CSharp.csprojAssemblyReference.cache".
/home/alt3r3d/.vscode/extensions/ms-vscode.csharp-1.21.0/.omnisharp/1.34.0/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(3450,5): Error: Could not write lines to file "/Debug/Assembly-CSharp.csproj.CoreCompileInputs.cache". Could not find a part of the path "/Debug/Assembly-CSharp.csproj.CoreCompileInputs.cache".
[fail]: OmniSharp.MSBuild.ProjectManager
Attempted to update project that is not loaded: /home/alt3r3d/UnityProjects/some random test/Assembly-CSharp.csproj

Categories

Resources