.NET: Difference between revisions

From ArchWiki
m (Removed the unnecessary comment and updated to latest version.)
m (→‎Install PowerShell Core: Moved link to bottom of section)
 
(63 intermediate revisions by 39 users not shown)
Line 1: Line 1:
[[Category:Framework]]
[[Category:Frameworks]]
[[ja:.NET Core]]
[[ja:.NET]]
[[zh-hans:.NET Core]]
[[zh-hans:.NET]]
'''.NET Core''' is a new FOSS software framework from Microsoft for C#, Visual Basic, and F#. It is designed to be cross-platform, modular and apt for modern applications, as opposed to its predecessor, the .NET Framework.
'''.NET''' (previously named .NET Core) is a FOSS software framework from Microsoft for C#, Visual Basic, and F#. It is designed to be cross-platform, modular and apt for modern applications, as opposed to its predecessor, the .NET Framework.
 
.NET source is available at [https://github.com/dotnet/dotnet dotnet/dotnet] on GitHub.


== Installation ==
== Installation ==


If you only want to run .NET Core managed applications, install the {{AUR|dotnet-runtime-2.0}} package.  
If you only want to run .NET managed applications, [[install]] the {{Pkg|dotnet-runtime}} package.
 
To build apps with .NET, install {{Pkg|dotnet-sdk}} as well.
 
Lastly, to build dynamic web sites, applications, and services using ASP.NET Core, install {{Pkg|aspnet-runtime}}.
 
Microsoft recommends using [[Visual Studio Code]] , their [https://electron.atom.io/ Electron]-based IDE, to build & debug .NET apps.
 
{{Tip|Add {{ic|~/.dotnet/tools}} to {{ic|PATH}}, otherwise dotnet tools will not work from shell.}}
 
To use .NET 6.0 instead suffix above package with "-6.0" such as {{Pkg|dotnet-runtime-6.0}}, {{Pkg|dotnet-sdk-6.0}} and {{Pkg|aspnet-runtime-6.0}}
=== Version differences ===
 
.NET SDKs are published under several version schemes. Only SDK versions {{ic|1xx}} can be built from source and will be available in the official repositories. Should you require any other version you will need one of the {{ic|*-bin}} packages from AUR.
 
=== Install multiple versions manually ===
 
You can install multiple versions of the .NET SDK or runtime side by side by using the [https://dot.net/v1/dotnet-install.sh dotnet-install.sh] script provided by the .NET Foundation. You can find the documentation of the script [https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script here].
 
For instance, this command would install the latest version found in the "STS"(Standard Term Support) channel in {{ic|/usr/share/dotnet}}:
 
# ./dotnet-install.sh --install-dir /usr/share/dotnet -channel STS -version latest
 
You may want to simulate the installation first by using the {{ic|-Dryrun}} flag.
 
Once installed, you can verify the SDKs available:
 
{{hc|$ dotnet --list-sdks|
2.2.108 [/usr/share/dotnet/sdk]
3.0.103 [/usr/share/dotnet/sdk]
}}
 
{{hc|$ dotnet --version|
3.0.103
}}
 
=== Uninstall manually installed version ===
 
You may want to remove outdated versions installed with {{ic|dotnet-install.sh}}. The automated [https://docs.microsoft.com/en-us/dotnet/core/additional-tools/uninstall-tool .NET Uninstall Tool] does still not support Linux, so the desinstallation has to be done manually.
 
{{hc|$ dotnet --list-sdks|
5.0.100 [/usr/share/dotnet/sdk]
5.0.102 [/usr/share/dotnet/sdk]
}}
 
Desinstallation of the sdk:
 
$ SDK_VERSION="5.0.100"
$ DOTNET_UNINSTALL_PATH="/usr/share/dotnet"
# rm -rf $DOTNET_UNINSTALL_PATH/sdk/$SDK_VERSION
 
Using {{ic|dotnet-install.sh}} also dotnet host and shared packages are getting installed, which may have to get removed additionally depending on the release.
 
Complete deinstallation of the .NET Version (sdk, host, shared):
 
$ SDK_VERSION="5.0.100"
$ DOTNET_VERSION="5.0.0"
$ DOTNET_UNINSTALL_PATH="/usr/share/dotnet"
# rm -rf $DOTNET_UNINSTALL_PATH/sdk/$SDK_VERSION
# rm -rf $DOTNET_UNINSTALL_PATH/shared/Microsoft.NETCore.App/$DOTNET_VERSION
# rm -rf $DOTNET_UNINSTALL_PATH/shared/Microsoft.AspNetCore.All/$DOTNET_VERSION
# rm -rf $DOTNET_UNINSTALL_PATH/shared/Microsoft.AspNetCore.App/$DOTNET_VERSION
# rm -rf $DOTNET_UNINSTALL_PATH/host/fxr/$DOTNET_VERSION
 
=== Install multiple versions via AUR ===
 
Some of the AUR dotnet packages are made to be installed alongside each other. Only one host package ({{aur|dotnet-host-bin}} or {{pkg|dotnet-host}}) is needed containing the command-line tool and you can install any of the available SDKs and Runtimes (latest packages of all major versions) next to it. List of compatible packages:
 
* {{aur|dotnet-host-bin}}, {{aur|dotnet-runtime-bin}}, {{aur|aspnet-runtime-bin}}, {{aur|dotnet-sdk-bin}}
* {{aur|dotnet-host-preview-bin}}, {{aur|dotnet-runtime-preview-bin}}, {{aur|aspnet-runtime-preview-bin}}, {{aur|dotnet-sdk-preview-bin}}
* {{aur|dotnet-runtime-7.0-bin}}, {{aur|aspnet-runtime-7.0-bin}}, {{aur|dotnet-sdk-7.0-bin}},
* {{aur|dotnet-runtime-3.0}}, {{aur|aspnet-runtime-3.0}}, {{aur|dotnet-sdk-3.0}},
* {{aur|dotnet-runtime-2.2}}, {{aur|aspnet-runtime-2.2}}, {{aur|dotnet-sdk-2.2}}, {{aur|dotnet-sdk-2.2-vs2017}}
* {{aur|dotnet-runtime-2.1}}, {{aur|aspnet-runtime-2.1}}, {{aur|dotnet-sdk-2.1}}
 
=== Install PowerShell Core ===
 
You can install PowerShell Core as a "global" tool also [https://devblogs.microsoft.com/powershell/introducing-powershell-as-net-global-tool/] [https://github.com/powershell/powershell]
 
# dotnet tool install --global PowerShell
 
to update to the current version
# dotnet tool update --global PowerShell
 
See also [[PowerShell]].
 
== Telemetry ==
 
The Microsoft build of the .NET SDK collects telemetry, by default. AUR .NET SDK packages (the {{ic|*-bin}} variants) are based on Microsoft builds of .NET. .NET runtime components do not collect telemetry in any scenario.
 
Community builds (including those in Arch; starting with .NET 7) do not collect telemetry, per a [https://github.com/dotnet/sdk/pull/25935 change to the .NET SDK] by Red Hat.
 
Telemetry can be disabled by [[Environment variables|setting environment variable]] {{ic|1=DOTNET_CLI_TELEMETRY_OPTOUT=1}}.
 
== Tab-Completion ==
 
All dotnet programs that use {{ic|System.CommandLine.Parser}} to parse their arguments have auto-complete support. Enabling it just requires adding a few lines to your {{ic|.bashrc}} / {{ic|.zshrc}} file, as described in [https://docs.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete#zsh their documentation]. Instructions for standalone binaries are [https://github.com/dotnet/command-line-api/blob/main/docs/dotnet-suggest.md here].
 
== Troubleshooting ==
 
=== It was not possible to find any compatible framework version ===
 
If you get the following error when you try to run a newly created project, you no longer need to set a {{ic|DOTNET_ROOT}} variable as described in the solutions of various GitHub issues. Arch's dotnet package (as of 3.1) installs it to the Microsoft recommended location of {{ic|/usr/share/dotnet}}.
 
{{hc|$ dotnet run|output=
 
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found.
  - No frameworks were found.
 
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=arch-x64
}}
 
This is caused because the runtime is shipped as a separate package in Arch. You just need to make sure you have the {{Pkg|aspnet-runtime}} package installed as well.
 
=== "the required library libhostfxr.so could not be found" error ===
 
Some of the dotnet SDK tools (for example ''libman'', ''dotnet-watch'' etc.) may expect you to have the environment variable {{ic|DOTNET_ROOT}} pre-configured. If it is not, an error like this one could be observed: [https://github.com/dotnet/cli/issues/9114]
 
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 [/home/my_user/.dotnet/tools/.store/microsoft.web.librarymanager.cli/1.0.172/microsoft.web.librarymanager.cli/1.0.172/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.
 
The workaround is to manually export {{ic|DOTNET_ROOT}} in your shell:
 
{{hc|1=~/.bashrc|2=
export DOTNET_ROOT=/opt/dotnet
}}
 
=== Error MSB4019: The imported project "/usr/share/dotnet/sdk/.../Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.Common.targets" was not found. Confirm that the expression in the Import declaration ... is correct, and that the file exists on disk. ===
 
This happens after an update. The currently running shell / login session is storing environment variables for the dotnet SDK version different from one installed. Restarting the shell or logging in again should fix this.
 
=== SDK specified could not be found ===
 
This is believed to be caused by a conflict between the Mono and MSBuild SDK libs and the dotnet ones. To fix this export the path manually in your shell (replacing the version number as necessary) e.g:
 
{{hc|1=~/.bashrc|2=
export MSBuildSDKsPath=$( echo /usr/share/dotnet/sdk/3.*/Sdks );
}}
 
=== dotnet command still installed ===


To build apps with .NET Core, install {{AUR|dotnet-sdk-2.0}} as well.
Installed packages do not uninstall dotnet-host, so uninstall {{Pkg|dotnet-host}}


Microsoft recommends using [[Visual Studio Code]] , their [https://electron.atom.io/ Electron]-based FOSS IDE, to build & debug .NET Core apps.
== See also ==


== External links ==
* [https://dotnet.microsoft.com/ .NET homepage]
* [https://www.microsoft.com/net/core/platform .NET Core homepage]
* [https://github.com/dotnet The .NET Foundation]
* [https://github.com/dotnet The .NET Foundation]
* [https://docs.microsoft.com/en-us/dotnet/api/index .NET API Browser]
* [https://docs.microsoft.com/en-us/dotnet/api/index .NET API Browser]

Latest revision as of 06:01, 13 February 2024

.NET (previously named .NET Core) is a FOSS software framework from Microsoft for C#, Visual Basic, and F#. It is designed to be cross-platform, modular and apt for modern applications, as opposed to its predecessor, the .NET Framework.

.NET source is available at dotnet/dotnet on GitHub.

Installation

If you only want to run .NET managed applications, install the dotnet-runtime package.

To build apps with .NET, install dotnet-sdk as well.

Lastly, to build dynamic web sites, applications, and services using ASP.NET Core, install aspnet-runtime.

Microsoft recommends using Visual Studio Code , their Electron-based IDE, to build & debug .NET apps.

Tip: Add ~/.dotnet/tools to PATH, otherwise dotnet tools will not work from shell.

To use .NET 6.0 instead suffix above package with "-6.0" such as dotnet-runtime-6.0, dotnet-sdk-6.0 and aspnet-runtime-6.0

Version differences

.NET SDKs are published under several version schemes. Only SDK versions 1xx can be built from source and will be available in the official repositories. Should you require any other version you will need one of the *-bin packages from AUR.

Install multiple versions manually

You can install multiple versions of the .NET SDK or runtime side by side by using the dotnet-install.sh script provided by the .NET Foundation. You can find the documentation of the script here.

For instance, this command would install the latest version found in the "STS"(Standard Term Support) channel in /usr/share/dotnet:

# ./dotnet-install.sh --install-dir /usr/share/dotnet -channel STS -version latest

You may want to simulate the installation first by using the -Dryrun flag.

Once installed, you can verify the SDKs available:

$ dotnet --list-sdks
2.2.108 [/usr/share/dotnet/sdk]
3.0.103 [/usr/share/dotnet/sdk]
$ dotnet --version
3.0.103

Uninstall manually installed version

You may want to remove outdated versions installed with dotnet-install.sh. The automated .NET Uninstall Tool does still not support Linux, so the desinstallation has to be done manually.

$ dotnet --list-sdks
5.0.100 [/usr/share/dotnet/sdk]
5.0.102 [/usr/share/dotnet/sdk]

Desinstallation of the sdk:

$ SDK_VERSION="5.0.100"
$ DOTNET_UNINSTALL_PATH="/usr/share/dotnet"
# rm -rf $DOTNET_UNINSTALL_PATH/sdk/$SDK_VERSION

Using dotnet-install.sh also dotnet host and shared packages are getting installed, which may have to get removed additionally depending on the release.

Complete deinstallation of the .NET Version (sdk, host, shared):

$ SDK_VERSION="5.0.100"
$ DOTNET_VERSION="5.0.0"
$ DOTNET_UNINSTALL_PATH="/usr/share/dotnet"
# rm -rf $DOTNET_UNINSTALL_PATH/sdk/$SDK_VERSION
# rm -rf $DOTNET_UNINSTALL_PATH/shared/Microsoft.NETCore.App/$DOTNET_VERSION
# rm -rf $DOTNET_UNINSTALL_PATH/shared/Microsoft.AspNetCore.All/$DOTNET_VERSION
# rm -rf $DOTNET_UNINSTALL_PATH/shared/Microsoft.AspNetCore.App/$DOTNET_VERSION
# rm -rf $DOTNET_UNINSTALL_PATH/host/fxr/$DOTNET_VERSION

Install multiple versions via AUR

Some of the AUR dotnet packages are made to be installed alongside each other. Only one host package (dotnet-host-binAUR or dotnet-host) is needed containing the command-line tool and you can install any of the available SDKs and Runtimes (latest packages of all major versions) next to it. List of compatible packages:

Install PowerShell Core

You can install PowerShell Core as a "global" tool also [1] [2]

# dotnet tool install --global PowerShell

to update to the current version

# dotnet tool update --global PowerShell

See also PowerShell.

Telemetry

The Microsoft build of the .NET SDK collects telemetry, by default. AUR .NET SDK packages (the *-bin variants) are based on Microsoft builds of .NET. .NET runtime components do not collect telemetry in any scenario.

Community builds (including those in Arch; starting with .NET 7) do not collect telemetry, per a change to the .NET SDK by Red Hat.

Telemetry can be disabled by setting environment variable DOTNET_CLI_TELEMETRY_OPTOUT=1.

Tab-Completion

All dotnet programs that use System.CommandLine.Parser to parse their arguments have auto-complete support. Enabling it just requires adding a few lines to your .bashrc / .zshrc file, as described in their documentation. Instructions for standalone binaries are here.

Troubleshooting

It was not possible to find any compatible framework version

If you get the following error when you try to run a newly created project, you no longer need to set a DOTNET_ROOT variable as described in the solutions of various GitHub issues. Arch's dotnet package (as of 3.1) installs it to the Microsoft recommended location of /usr/share/dotnet.

$ dotnet run
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found.
  - No frameworks were found.

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=arch-x64

This is caused because the runtime is shipped as a separate package in Arch. You just need to make sure you have the aspnet-runtime package installed as well.

"the required library libhostfxr.so could not be found" error

Some of the dotnet SDK tools (for example libman, dotnet-watch etc.) may expect you to have the environment variable DOTNET_ROOT pre-configured. If it is not, an error like this one could be observed: [3]

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 [/home/my_user/.dotnet/tools/.store/microsoft.web.librarymanager.cli/1.0.172/microsoft.web.librarymanager.cli/1.0.172/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.

The workaround is to manually export DOTNET_ROOT in your shell:

~/.bashrc
export DOTNET_ROOT=/opt/dotnet

Error MSB4019: The imported project "/usr/share/dotnet/sdk/.../Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.Common.targets" was not found. Confirm that the expression in the Import declaration ... is correct, and that the file exists on disk.

This happens after an update. The currently running shell / login session is storing environment variables for the dotnet SDK version different from one installed. Restarting the shell or logging in again should fix this.

SDK specified could not be found

This is believed to be caused by a conflict between the Mono and MSBuild SDK libs and the dotnet ones. To fix this export the path manually in your shell (replacing the version number as necessary) e.g:

~/.bashrc
export MSBuildSDKsPath=$( echo /usr/share/dotnet/sdk/3.*/Sdks );

dotnet command still installed

Installed packages do not uninstall dotnet-host, so uninstall dotnet-host

See also