Update .NET Core Tools - visual-studio-2019

I'm trying to use EntityFrameworkCore#3.1. In order to do this at this point I already have:
- Installed Visual Studio 2019 Preview
- Installed the .NET Core 3.1 Runtime
- Installed the .NET Core 3.1 SDK
Now I still can't run the command dotnet ef migrations add xxx. It's saying that I have to update the dotnet tools. So I run the following command in an administrator powershell:
PS C:\WINDOWS\system32> dotnet tool update --global dotnet-ef
Tool 'dotnet-ef' was reinstalled with the latest stable version (version '3.0.0')
Okay, not including the preview versions. So I try to specify the version explicitly:
PS C:\WINDOWS\system32> dotnet tool update --global dotnet-ef --version="3.1.0-preview1.19506.2"
error NU1202: Package dotnet-ef 3.1.0-preview1.19506.2 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1) / any. Package dotnet-ef 3.1.0-preview1.19506.2 supports: netcoreapp3.1 (.NETCoreApp,Version=v3.1)
Tool 'dotnet-ef' failed to update due to the following:
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.
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
Now it's saying that a .NET Core 3.1 tool is not compatible with the .NET Core 3.1 runtime.
However, if I do a simple version check:
PS C:\WINDOWS\system32> dotnet --version
3.1.100-preview1-014459
PS C:\WINDOWS\system32> dotnet ef --version
Entity Framework Core .NET Command-line Tools
3.0.0
I can see that the EntityFrameworkCore.Tools is still at version 3.0.0 instead of 3.1.0 (which tools version is installed in my project).
Am I still missing something or is this a bug?

Thanks to #lars-haupt-hansen for pointing me to the bug, I followed the trail to the PR which shows it was merged into "aspnet:release/3.1". The latest 3.1 is still a preview (preview3) [edit: it's out of preview]. You can find and download the latest SDK here.
To use it in Visual Studio projects, you have to
install the SDK from the above link;
go to Tools > Options > Environment > Preview Features and enable "Use previews of the .NET Core SDK"; (not required for 3.1 anymore)
restart VS (not required for 3.1 anymore)
Go to each project properties, and then you can choose the Target Framework .NET Core 3.1
Then to install EF Core via the command line, run dotnet tool install --global dotnet-ef from your project directory.

dotnet tool install -g dotnet-ef --version 3.0.0-preview4.19216.3
dotnet tool install --global dotnet-ef --version 3.0.0-preview8.19405.11

Related

A fatal error occurred. The required library libhostfxr.dylib could not be found

I'm working on ASP.NET Project with .NET 5.0. For Database creation, I've run the command
dotnet tool install --global dotnet-ef
After the installing, when I run this command:
dotnet ef
I got that error
A fatal error occurred. The required library libhostfxr.dylib could
not be found. If this is a self-contained application, that library
should exist in
[/Users/afshalathar/.dotnet/tools/.store/dotnet-ef/6.0.0/dotnet-ef/6.0.0/tools/netcoreapp3.1/any/].
If this is a framework-dependent application, install the runtime in
the global location [/usr/local/share/dotnet/x64] or use the
DOTNET_ROOT environment variable to specify the runtime location or
register the runtime location in [/etc/dotnet/install_location].
The .NET runtime can be found at:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=osx.11.1-x64&apphost_version=5.0.11
I'm using Mac M1
As mentioned here, first uninstall dotnet-ef and then reinstall it using the -a arm64 option:
dotnet tool uninstall dotnet-ef --global
dotnet tool install dotnet-ef --global -a arm64
This worked for me.
Update
This fixes the problem permanently:
dotnet tool uninstall dotnet-ef -g
dotnet tool install dotnet-ef -a arm64 -g
You can also try installing EF tool locally
CD to your source directory and do this:
dotnet new tool-manifest
dotnet tool install dotnet-ef
In this way, it works even with the .Net 5/6 arm64.
There's a bug in the arm64 tool installer that references the x64 version.
Late to the party, but I had the same issue on a M1 Macbook. Strangely enough, the following steps worked for me:
sudo dotnet tool uninstall dotnet-ef --global
dotnet tool update --global dotnet-ef
I was quite desperate with this bug until I found https://developercommunity.visualstudio.com/t/libhostfxrdylib-not-signed/909971.
I could resolve the libhostfxr.dylib error when calling dotnet ef command. By simply fully updating my Visual Studio for Mac.
Problem: Some code signing issue with this file and macOS just moves it to some kind of quarantine (as far as I understood)
Solution: Open Visual Studio for Mac and install all the updates.
I first found the link on developercommunity and then thought it might just work and it really did.
If this helped you, you too might just be hooked to Jetbrains Rider. But installing dotnet via Rider does not fix the problem and also installing this extension https://plugins.jetbrains.com/plugin/18147-entity-framework-core-ui did NOT resolve it.
If you don't mind having Visual Studio for Mac also on your machine it's worth a shot.

Cannot create Q# projects

I'm new to quantum computing and I've been trying to follow instructions on https://learn.microsoft.com/en-us/azure/quantum/install-command-line-qdk?tabs=tabid-vscode to dive into this field, but I've run into a problem. Every time I'm trying to create a new Q# application project, I get the following error message
The project file cannot be opened. Unable to find package Microsoft.Quantum.Sdk. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages C:\Program Files\dotnet\sdk\5.0.202\Sdks\Microsoft.Quantum.Sdk\Sdk not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.
and I can't find that package myself either.
I've tried to install Microsoft.Quantum.Development.Kit-0.16.2104.138035 several times, with both .NET 3.1.408 and 5.0.202. I'm using VS 2019 16.9.4 Community Edition on Windows 10.
Looks like nuget.org is not listed as a valid package source in your computer, so dotnet can't find the QDK packages online.
Try running this command:
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
And then try building your Q# project again.
It's unclear to me why nuget.org is not listed as a source, though; it should be included by default when you install the .NET Core.

EntityFramework.Core.Tools nuget package installation error: "The process cannot access the file ef.exe because it is being used by another process"

While installing the package Microsoft.EntityFrameworkCore.Tools for using EF in my project using Nuget, I'm persistently running into the below error. Notice I didn't get any error while installing other related packages used for EF core
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Relational
Microsoft.EntityFrameworkCore.SqlServer
Here is the location of the file ef.exe
Basically the intention behind installing this package is to use EF command-line tools. I'm currently on Windows 10 and the .NET SDK installed on my machine is 3.1. I had previously 2 SDK's installed on my system(3.1 & 5.0). As per microsoft's documentaion, "The .NET CLI must choose an SDK version for every dotnet command. It uses the latest SDK installed on the machine by default." Therefore I went ahead and uninstalled .NET 5.0 SDK
Here are some of the solutions that I tried:
Deleting the package folder from '.nuget/packages/microsoft.entityframeworkcore.tools' & thereby the executable i.e. 'ef.exe' and reinstalling the same.
Installing the same package using dotnet cli.
Running Visual Studio 2019 as admin.
Deleted the folder "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions"
I have also tried some of the steps mentioned here on github: https://github.com/NuGet/Home/issues/1138
. Any kind of help would be really appreciated.
I have answered the detailed description of the solution here on microsoft's .NET Q&A platform.
'EntityFramework.Core.Tools' nuget package installation error

dotnet ef command not working after VS for Mac update

I've been using VS for Mac for a while now with EF Core 2.2 and everything's been going alright. Today I updated VS for Mac since it was really out of date, and after the update I can no longer run the dotnet ef command:
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET Core program, but dotnet-ef does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
Note that this is .NET Core 2.2 and EF Core 2.2, not 3.0. Everything I've read online is specific to 3.0, so could someone please instruct me on how to get this command to finally work? Here are some things I've already tried:
wiping the packages and re-installing them
running dotnet restore
explicitly adding the Microsoft.EntityFrameworkCore.Design package
explicitly adding the Microsoft.EntityFrameworkCore.Tools package
explicitly re-installing Microsoft.EntityFrameworkCore
rebooting VS for Mac
rebooting the Mac itself
Had same issue too, you don't have to uninstall v3.0. Eventually found out that the dotnet ef isn't longer part of the .netcore SDK.
You will need to install the ef tool for the specific version you want (In my case, 2.2). Run the command below on terminal:
dotnet tool install --global --version 2.2 dotnet-ef
Note that I specified global, you can as well specify local.
You should get an output with some information on how to add it to your profile and finally run:
zsh -l
and export to PATH:
export PATH="$PATH:/Users/username/.dotnet/tools"
For more information:
https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet
Breaking changes in dotnet-ef
For those that are having this issue after switching to zsh (for example after upgrading to macOS Catalina): the default path for globally installed tools is not recognised by zsh and now requires to reference the relevant path in your profile (.zshrc).
This can be done by adding the following lines:
# Add .NET Core SDK global tools/packages
export PATH=$HOME/.dotnet/tools:$PATH"
See further background on why this was different from bash in: https://github.com/dotnet/cli/issues/9321
Figured it out. When I updated VS for Mac it installed .NETCore SDK v3.0, so every time I ran the dotnet command it was using the version 3 executable. After removing that SDK version (by following these instructions https://learn.microsoft.com/en-us/dotnet/core/versions/remove-runtime-sdk-versions?tabs=macos#uninstalling-net-core), it’s now using the correct version for the project and the dotnet ef command is working again
Try this:
dotnet tool uninstall dotnet-ef -g
dotnet tool install dotnet-ef -a arm64 -g

What's the difference between SDK and Runtime in .NET Core?

I've read many articles, including this one, yet I can't still figure out what's the difference, and they have not explained it either in simple terms or at all.
Can someone please clarify what's the difference between .NET SDK and .NET Runtime?
Update: Using comparisons would be very appreciated. Analogy alongside simple English is highly educational.
According to the .Net Core Guide, .NET Core is composed of the following items
A .NET runtime, which provides a type system, assembly loading, a garbage collector, native interop and other basic services.
A set of framework libraries, which provide primitive data types, app composition types and fundamental utilities.
A set of SDK tools and language compilers that enable the base developer experience, available in the .NET Core SDK.
The 'dotnet' app host, which is used to launch .NET Core apps. It selects the runtime and hosts the runtime, provides an assembly loading policy and launches the app. The same host is also used to launch SDK tools in much the same way.
The SDK is all of the stuff that is needed/makes developing a .NET Core application easier, such as the CLI and a compiler.
The runtime is the "virtual machine" that hosts/runs the application and abstracts all the interaction with the base operating system.
Only the latter is required to run the application, but the former is needed to develop the application.
Runtime: to run apps
SDK (Runtime + Tooling): to build and run apps
I'm not inventing anything here. Just copy-pasting the definitions from https://dotnet.microsoft.com/download
The software development kit (SDK) includes everything you need to build and run .NET Core applications, using command-line tools and any editor (like Visual Studio).
The runtime includes everything you need to run .NET Core applications. The runtime is also included in the SDK.
Sharing from Rick Strahl's post: Which .NET Core Runtime Download do you need?
Only the .NET Core Runtime is required to run an application and provides information about the install.
To develop, build and publish an application will require an SDK.
dotnet.exe installs with a runtime install, but it only provides core features to provide info to run an application and provide info about the install: dotnet mydll.dll and dotnet --info. To build, publish or do anything else you need to install the SDK.
Running the following command will provide information about the install:
dotnet --info
If the command fails it means you do not have the .NET Core runtime installed or available in the system's PATH.
Below is a sample output of the command.
$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.2.101
Commit: 236713b0b7
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.2.101/
Host (useful for support):
Version: 2.2.0
Commit: 1249f08fed
.NET Core SDKs installed:
2.1.4 [/usr/local/share/dotnet/sdk]
2.1.302 [/usr/local/share/dotnet/sdk]
2.2.101 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
The output tells you:
The installed SDK version
The active runtime version that's running this dotnet command
A list of all installed runtimes and SDKs
Installing an SDK also installs the runtime.
macOS homebrew specific
Installing the homebrew-cask dotnet will conflict with the dotnet-sdk, so to get both the runtime, and the sdk install dotnet-sdk
brew cask install dotnet-sdk
In short, the runtime will allow your OS to run compiled C-Sharp, C# programs, and the sdk will allow you to compile programs written in C-Sharp, C#.
It's important to understand that you can have multiple runtimes and multiple SDKs installed and each project can use a different one. The runtime is determined by your project's runtime specifier in the .csproj file:
<TargetFramework>netcoreapp2.1</TargetFramework>
The SDK is either the last globally installed SDK which is the default, or you can explicitly override the SDK in a global.json placed in the solution root folder. The following explicitly forces my project to use the last RC SDK, instead of the RTM version:
{
"sdk": {
"version": "2.1.300-rc.31211"
}
}
Generally, there should be no need to use a specific lower SDK version as the SDK is backwards compatible and can compile various versions of .NET Core applicatino back to v1.0. IOW, it's OK to use the latest SDK in almost all cases.
.NET Core Runtimes
The .NET Core Runtimes are the smallest self-contained and specific component and contain the absolute minimum to run just .NET Core on a specific platform.
Note it a runtime install does not include the ASP.NET Core meta package runtime dependencies, so if your application references Microsoft.AspNetCore.App or Microsoft.AspNetCore.All you have to seperately download the ASP.NET Core package. However, if you explicitly reference all ASP.NET Core Nuget packages rather than using the meta packages, those packages are deployed as part of your application and it can run with just the runtime.
Essentially you are trading installation package size vs. a runtime pre-install requirement.
References:
Which .NET Core Runtime Download do you need?
The SDK is all of the stuff that is needed/makes developing a .NET Core application easier, such as the CLI and a compiler.
The runtime is the "virtual machine" that hosts/runs the application and abstracts all the interaction with the base operating system.
As summary:
If you install SDK, you will have everything you need for development and running the app.
adding to stormwild's answer in case you have only the .Net Core Runtime installed you will receive the following output from dotnet --info
>PS C:\Users\Administrator> dotnet --info
>
>Host (useful for support):
> Version: 2.2.3
> Commit: 6b8ad509b6
>
>.NET Core SDKs installed:
> No SDKs were found.
>
>.NET Core runtimes installed:
> Microsoft.NETCore.App 2.2.3 [C:\Program
>Files\dotnet\shared\Microsoft.NETCore.App]
Runtime is enough if we want to run just application on hardware, otherwise to develop and run we need SDK (which includes runtime and tooling).
SDK ==> to build and run .NET apps
Runtime ==> to run .NET apps
Easy! :)
The SDK usually includes documentation and other help files. The runtime contains only the binary files for the installation.
When you install SDK you also get runtime in that. Check this below, this is what gets installed when we install SDK.
The following were installed at C:\Program Files\dotnet
• .NET Core SDK 2.2.100
• .NET Core Runtime 2.2.0
• ASP.NET Core Runtime 2.2.0
SDK is required to compile source code and generate bytecode/Intermediate Language Instruction for a specific target OS/runtime. SDK is not tightly coupled to target OS. For ex - SDK installed on Windows can generate bytecode for Linux.
dotnet build --runtime ubuntu.18.04-x64
Runtime is required to run bytecode on a specific OS. Runtime is specific to OS. Runtime for Ubuntu is different than Windows.
Runtime is what makes .Net Core special. Runtime allows .Net apps to be "Write Once, Run Anywhere" similar to Java.

Resources