VSCode Unity OmniSharp .NETFramework not found - c#

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

Related

It was not possible to run: dotnet run in visual studio code (macOS)

I have installed:
Host (useful for support):
Version: 6.0.1
Commit: 3a25a7f1cc
.NET SDKs installed:
No SDKs were found.
.NET runtimes installed:
Microsoft.NETCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
but, when I run: dotnet run show this message ->
Could not execute because the application was not found or a
compatible .NET SDK is not installed. Possible reasons for this
include: * You intended to execute a .NET program:
The application 'run' does not exist. * You intended to execute a .NET SDK command:
It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
https://aka.ms/dotnet-download
if you have any suggestion how to fix it and run API? Best! 🤗
It's a common cause of confusion that the dotnet run command needs an SDK to work. dotnet run, unlike what the name might suggest, is a command for developers working on their applications. It rebuilds and runs their application, during a development phase.
If you already have a .NET application built (or published as it's technically called) and you just want to run it, you should use this style of command: dotnet /path/to/your.dll. That is, just run dotnet against the main dll of the application.
I found issue and fix it. it works for me now. just install dotnet-sdk-yourversion.
brew tap isen-ng/dotnet-sdk-versions
brew install --cask dotnet-sdk2-2-100
dotnet --list-sdks
You can find it here: https://github.com/isen-ng/homebrew-dotnet-sdk-versions

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).

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.

.net core not found even though it is installed. Should i restart my Mac to use microsoft stack?

I have .net core 2.1 installed as you can see as follows;
➜ Util.Samples.Webs git:(master) ✗ dotnet --version
2.1.200
➜ Util.Samples.Webs git:(master) ✗
When I run visual studio to run this project.
I get an error:
Restore failed for 'Microsoft.NETCore.App (>= 2.1.0)'.
Restore failed.
When I look at options of the project. I see .NET core 2.1 (Not installed) but it is installed as you see above.
I tried changing TargetFramework in my .proj file but no luck.
Should I restart my Mac just like restarting Windows? How can I resolve this?
Here is dotnet --info output:
➜ Util git:(master) ✗ dotnet --info
.NET Command Line Tools (2.1.200)
Product Information:
Version: 2.1.200
Commit SHA-1 hash: 2edba8d7f1
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.13-x64
Base Path: /usr/local/share/dotnet/sdk/2.1.200/
Microsoft .NET Core Shared Framework Host
Version : 2.0.7
Build : 2d61d0b043915bc948ebf98836fefe9ba942be11
➜ Util git:(master) ✗
Looks like you were a victim of .NET Core's rather bizarre versioning scheme. In this scheme, the SDK and Runtime have different versions that were diverging, but still close enough to be confusing. In your case, you have now seen a SDK 2.1 that can not target .NET Core (Runtime) 2.1. This was "fixed" (some discussion here), but the upshot is the versions are still confusing and dotnet --info is your best best to find out which SDK and Runtime versions are supported by your installation of .NET Core.
You are trying to build a netcoreapp2.1 (aka .NET Core 2.1) project. You need an SDK that knows about it.
But the SDK you have (which is version 2.1.200) is actually an older SDK that does not know about .NET Core 2.1! The SDK versions that know about .NET Core 2.1 are versioned 2.1.300 or later. You need a newer .NET Core SDK version, which will include a more recent .NET Core Runtime 2.1 version as well.
You should have a good enough version of .NET Core if dotnet --info says something about "2.1" in a "runtime" section.

.Net Core lastest SDK installed but getting 'Framework 'Microsoft.AspNetCore.App', version '2.1.0' was not found

I want to use .Net Core on linux and do have the latest releases:
> sudo pacman -Qs dotnet
local/dotnet-host 2.1.0-1
A generic driver for the .NET Core Command Line Interface
local/dotnet-runtime 2.1.0-1
The .NET Core runtime
local/dotnet-sdk 2.1.300-1
The .NET Core SDK
> dotnet --version
2.1.300
But when I want to run my sample application (just the razor template):
> dotnet run
Using launch settings from /home/user/src/WebRepTrack/Properties/launchSettings.json...
It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.App', version '2.1.0' was not found.
- Check application dependencies and target a framework version installed at:
/opt/dotnet/
- Installing .NET Core prerequisites might help resolve this problem:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
https://aka.ms/dotnet-download
Looking at this issue, the problem was that the user did not have the appropiate sdk/runtime version installed, but that's not the cause of my issue, isnt it?
Edit: After looking into the dotnet-core repo at github, I realized that MS now ships the asp.net core support with the package aspnetcore-runtime-2.1.0 (whereas before, it was shipped with the core-runtime). The ArchLinux package dotnet-runtime does not include this change! See here for more details:
https://bugs.archlinux.org/task/58806
After looking into the dotnet-core repo at github, I realized that MS now ships the asp.net core support with the package aspnetcore-runtime-2.1.0 (whereas before, it was shipped with the core-runtime). The ArchLinux package dotnet-runtime does not include this change! See here for more details:

Categories