.NET SDK requirement for Saturn - f#

When following the "How to start" guide for Saturn:
https://saturnframework.org/tutorials/how-to-start.html
Step 4 says to run:
dotnet tool restore
Here's the result of running that on my system:
PS C:\Users\dharm\Dropbox\Documents\VisualStudio\SaturnSample> dotnet tool restore
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 'tool' does not exist.
* You intended to execute a .NET SDK command:
A compatible installed .NET SDK for global.json version [3.1.200] from [C:\Users\dharm\Dropbox\Documents\VisualStudio\SaturnSample\global.json] was not found.
Install the [3.1.200] .NET SDK or update [C:\Users\dharm\Dropbox\Documents\VisualStudio\SaturnSample\global.json] with an installed .NET SDK:
3.1.405 [C:\Program Files\dotnet\sdk]
5.0.101 [C:\Program Files\dotnet\sdk]
5.0.102 [C:\Program Files\dotnet\sdk]
I see a few ways forward:
Install .NET SDK version 3.1.200 (even though I already have 3.1.405)
Update global.json to be the following:
{
"sdk": {
"version": "3.1.405"
}
}
Update global.json to be the following (allows for versions more recent than 3.1.200):
{
"sdk": {
"version": "3.1.200",
"rollForward": "latestFeature"
}
}
Which of these would be recommended for Saturn?
UPDATE
Looks like there's a pull-request regarding this issue:
https://github.com/SaturnFramework/Saturn.Template/pull/29
UPDATE 2021-02-10
The above mentioned pull request isn't ideal since it requires a specific version of the .NET SDK.
I've submitted a pull-request to go with the rollForward option:
https://github.com/SaturnFramework/Saturn.Template/pull/31

Related

Docker - dotnet no framework found

Trying to run a dotnet core based docker container on a windows 2022 server that's setup with WSL2 (Ubuntu). Running the container fails with the below error message indicating I don't have any dotnet frameworks installed...
You must install or update .NET to run this application.
App: /app/TodoApi.dll
Architecture: x64
Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
.NET location: /usr/share/dotnet/
No frameworks were found.
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=6.0.0&arch=x64&rid=debian.11-x64
Running dotnet --info I can see I have version sdk - 6.0.400, runtime - 6.0.8
azureuser#myworkstation01:/mnt/c/Users/azureuser$ dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.400
Commit: 7771abd614
Runtime Environment:
OS Name: ubuntu
OS Version: 20.04
OS Platform: Linux
RID: ubuntu.20.04-x64
Base Path: /usr/share/dotnet/sdk/6.0.400/
global.json file:
Not found
Host:
Version: 6.0.8
Architecture: x64
Commit: 55fb7ef977
.NET SDKs installed:
6.0.400 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Checking in $PATH, i can see there is an environment variable for dotnet already...
azureuser#myworkstation01:/mnt/c/Users/azureuser$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files (x86)/dotnet/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/PowerShell/7/:/mnt/c/Users/azureuser/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/azureuser/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/azureuser/.dotnet/tools:/snap/bin:/home/azureuser/.dotnet/tools
I am using WSL2, I can see Docker is configured to use Ubuntu distro in the WSL integration.
I've config RollForward to LatestMajor in my dotnet core project property...
Is there anything obvious I am missing?
I upgraded ubuntu and had the same problem.
Try uninstalling dotnet and specifying the version you want to install.
Github Reference
$ sudo apt install aspnetcore-runtime-6.0=6.0.8-1 dotnet-apphost-pack-6.0=6.0.8-1 dotnet-host=6.0.8-1 dotnet-hostfxr-6.0=6.0.8-1 dotnet-runtime-6.0=6.0.8-1 dotnet-sdk-6.0=6.0.400-1 dotnet-targeting-pack-6.0=6.0.8-1
The WSL2 led me down a rabbithole. The issue was in the docker file itself, my baseimage didn't have the right aspnet core framework. This has been resolved using the following stackoverflow answer - The framework 'Microsoft.AspNetCore.App', version '6.0.0' (x64) was not found
Check for Project tag of .csproj file. If it's Sdk attribute is set to Microsoft.NET.Sdk.Web then this would be a reason for ASP.NET Core runtime requirement. Also check for libraries referencing Microsoft.AspNetCore.App.

HTTP Error 500.31 - Failed to load ASP.NET Core runtime , tried to install 3.1.0 in nuget but failed

HTTP Error 500.31 - Failed to load ASP.NET Core runtime
Common solutions to this issue:
The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.
Specific error detected by ANCM:
It was not possible to find any compatible framework version The framework 'Microsoft.AspNetCore.App', version '3.1.0' (x64) was not found. - The following frameworks were found: 6.0.1 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.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.AspNetCore.App&framework_version=3.1.0&arch=x64&rid=win10-x64
Troubleshooting steps:
Check the system event log for error messages
Enable logging the application process' stdout messages
Attach a debugger to the application process and inspect
For more information visit: https://go.microsoft.com/fwlink/?LinkID=2028526
To run an ASP.NET Core application on a machine, the appropriate runtime (or SDK) must be installed on that machine. In your case, you want to run a .NET Core 3.1 application on a machine that has only .NET 6.0 installed. Therefore, to run your ASP.NET Core 3.1 application, you must download and install the appropriate ASP.NET Core runtime (or for a Windows server with IIS, the appropriate hosting bundle).
You can also solve this in .runtimeconfig.json file
You can set your current version manually.
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.AspNetCore.App",
"version": "6.0.1"
},

Update .NET Core Tools

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

Building .a NET Core project using Jenkins always references the latest installed SDK version

I'm running a "Build a Visual Studio project or solution using MSBuild" on Jenkins for several projects to generate nuget packages.
The MSBuild used is the latest Visual Studio Build Tools
The version of the .NET Core sdk used in the project is 1.0.4
Company.Core.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
</Project>
However while executing a build the used SDK version is always the latest SDK installed on the machine (2.x).
C:\Program Files\dotnet\sdk\2.1.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5):
error NETSDK1064: Package Microsoft.CSharp, version 4.0.1 was not found.
It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.
[C:\Workspaces\Company.Core\Company.Core.csproj]
After uninstalling the 2.1.400 SDK version i get the error:
C:\ProgramFiles\dotnet\sdk\1.1.10\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(308,5):
error : Assets file 'C:\Workspaces\Company.Core\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. [C:\Workspaces\Company.Core\Company.Core.csproj]
The installation used to support .net Core 1.0.4 was .NET Core 1.0.4 & 1.1.1 SDK 1.0.1 using the instructions:
Windows Server Hosting
If you are looking to host stand-alone apps on
Windows Servers, the ASP.NET Core Module for IIS can be installed
separately on servers without installing .NET Core runtime. You can
download the Windows (Server Hosting) installer and run the following
command from an Administrator command prompt:
DotNetCore.1.0.4_1.1.1-WindowsHosting.exe OPT_INSTALL_LTS_REDIST=0
OPT_INSTALL_FTS_REDIST=0
I also added RuntimeFrameworkVersion in the csproj that had no effect.
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>^
global.json also gets ignored
{
"sdk": {
"version": "1.0.4"
}
}
It looks like you can specify the sdk version in a global.json file:
{
"sdk": {
"version": "1.0.4"
}
}
Source:
https://markheath.net/post/switching-between-netcore-sdk-versions
I think there's some confusion here. .NET Core consists of two almost separate components: the SDK and the Runtime. The SDK is used to build your code and the runtime is needed to run it.
They are versioned differently. For example, the latest SDK is 2.1.403, while the latest Runtime is 2.1.5.
A recent version of SDK can target any version of the runtime released before it. So, a 2.1.403 SDK can build applications that need 2.0 or 1.0 to run.
You can force a particular SDK to be used, by using the global.json file. You need to specify a version of the SDK that is already installed. dotnet new globaljson will generate something that you can edit the versions in. But you shouldn't need to do that. You can just use the latest SDK and ask it to build for an older runtime by setting the TargetFramework as you do.
If you do a dotnet restore, does the error NETSDK1064: Package Microsoft.CSharp, version 4.0.1 was not found. still stick around? The second error, Assets file 'C:\Workspaces\Company.Core\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. backs this up. The project.assets.json is created by dotnet restore. Could you simply be missing that step?

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