Running .NET application on OSX fails with "No frameworks were found" - c#

I'm attempting to compile and run a .net application on Mac OS (on our CI platform) but keep running into the following error message:
The framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
- No frameworks were found.
However, another .NET application (which from what I can see, has no differences with the target framework, and only small differences between the csproj contents) compiles and runs fine just before this application is compiled and run.
dotnet --list-sdks returns:
3.1.419 [/Users/username/.dotnet/sdk]
5.0.408 [/Users/username/.dotnet/sdk]
dotnet --list-runtimes returns:
Microsoft.AspNetCore.App 3.1.25 [/Users/username/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [/Users/username/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.25 [/Users/username/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [/Users/username/.dotnet/shared/Microsoft.NETCore.App]
So from this I can see that .NET 3.1 is installed, but why is the application unable to be executed? Am I missing something here? Would appreciate any help or pointers.
Thanks

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

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.

Problem when using dotnet-clear tool with framework dotnet core 3.1

I am currently developing code using the dotnet core 3.1 framework on a new pc.
I installed the latest version of the dotnet-clear tool using this code:
dotnet tool install --global dotnet-clear
When I use it, the following output is displayed.
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
- The following frameworks were found:
3.1.2 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.1.0&arch=x64&rid=win10-x64
The Microsoft.NETCore.App framework is installed during dotnet core installation.
From the message it would seem that I need to install dotnet core 2.1 but I was using dotnet core 3.1 and dotnet clear on the old pc.
Any idea how to solve the situation?

Dotnet test ignoring filter when on Linux

I'm using xunit, with trait attributes set on some of my tests. When running dotnet test I'm trying to filter by these traits. I have it working fine locally on my Windows machine but when I run the same command on my CI container then it doesn't filter my tests.
The command is:
dotnet test --filter Category=Integration
I'm using CircleCI with the container mcr.microsoft.com/dotnet/core/sdk:2.2
When I SSH to the box and try running the command, it just runs all of the tests.
dotnet --info from the container:
.NET Core SDK (reflecting any global.json):
Version: 2.1.700
Commit: c2ef055a0f
Runtime Environment:
OS Name: debian
OS Version: 9
OS Platform: Linux
RID: debian.9-x64
Base Path: /usr/share/dotnet/sdk/2.1.700/
Host (useful for support):
Version: 2.1.11
Commit: d6a5616240
.NET Core SDKs installed:
2.1.700 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.11 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.11 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.11 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
I've managed to resolve my issue just about. It appears it's a bug with the 16.1.0 SDK version (which dictates the version of vstest). As the issue was just on CI for me, I pinned the container I was using to
mcr.microsoft.com/dotnet/core/sdk#sha256:d0a71e1312be2618f320a7b7cc6d7423af3810542b3ffd35438108800ecfb958
which contains the 16.0.1 SDK. It's not the perfect fix but resolves my immediate issue.

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