「.NET」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(→‎Install multiple versions via AUR: タイトルだけ和訳)
(→‎インストール: 記事を追加)
 
(2人の利用者による、間の34版が非表示)
1行目: 1行目:
 
[[Category:フレームワーク]]
 
[[Category:フレームワーク]]
[[en:.NET Core]]
+
[[en:.NET]]
[[zh-hans:.NET Core]]
+
[[zh-hans:.NET]]
'''.NET Core''' は Microsoft 製の新しいオープンソース C#, Visual Basic, F# ソフトウェアフレームワークです。先行の .NET Framework と異なり、クロスプラットフォームで動作し近代的なアプリケーションに適した設計が行われています。
+
'''.NET'''(以前の名前は .NET Core) は Microsoft が提供する C#, Visual Basic, F# のための FOSS ソフトウェアフレームワークです。先行の .NET Framework と異なり、クロスプラットフォームでモジュール化され、近代的なアプリケーションに適した設計が行われています。
   
 
== インストール ==
 
== インストール ==
   
.NET Core で管理されるアプリケーションを実行したいだけの場合は {{Pkg|dotnet-runtime}} パッケージを[[インストール]]してください。
+
.NET マネージドアプリケーションを実行したいだけの場合は {{Pkg|dotnet-runtime}} パッケージを[[インストール]]してください。
   
.NET Core でアプリをビルドする場合は {{Pkg|dotnet-sdk}} パッケージもインストールしてください。
+
.NET でアプリをビルドする場合は {{Pkg|dotnet-sdk}} パッケージもインストールしてください。
   
  +
最後に、ASP.NET Core を使用して動的な Web サイト、アプリケーション、およびサービスを構築するには、{{Pkg|aspnet-runtime}}をインストールします。
Microsoft は .NET Core アプリをビルド・デバッグするときは [[Electron]] ベースのオープンソース IDE である [[Visual Studio Code]] を使うことを推奨しています。
 
   
  +
Microsoft は [[Visual Studio Code]](同社の [https://www.electronjs.org/ Electron] ベースの IDE)を使用して .NET アプリを構築・デバッグすることを推奨しています。
{{Tip|{{ic|PATH}} に {{ic|~/.dotnet/tools}} を追加してください。追加しない場合は、 dotnetツールはシェルから使うことができません。}}
 
   
  +
{{Tip|{{ic|PATH}} に {{ic|~/.dotnet/tools}} を追加してください。追加しない場合は、 dotnet ツールはシェルから使うことができません。}}
=== 複数のバージョンを手動でインストールする ===
 
   
  +
.NET 6.0、7.0、8.0 を使用したい場合は、上記パッケージにそれぞれ "-6.0"、"-7.0"、"-8.0" をサフィックスとして付けてください(例:{{Pkg|dotnet-runtime-8.0}}、{{Pkg|dotnet-sdk-8.0}}、{{Pkg|aspnet-runtime-8.0}})
You can install multiple versions of the .NET Core 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 "current" channel in {{ic|/usr/share/dotnet}}:
 
   
  +
.NET SDK は複数のバージョン体系で公開されています。{{ic|1xx}} バージョンの SDK のみがソースからビルド可能で、公式リポジトリで提供されます。それ以外のバージョンが必要な場合は、AUR にある {{ic|*-bin}} パッケージを使用する必要があります。
# ./dotnet-install.sh --install-dir /usr/share/dotnet -channel Current -version latest
 
   
  +
=== 複数バージョンの手動インストール ===
You may want to simulate the installation first by using the {{ic|-Dryrun}} flag.
 
   
  +
複数の .NET SDK やランタイムを共存させるには、.NET Foundation が提供する [https://dot.net/v1/dotnet-install.sh dotnet-install.sh] スクリプトを使用します。スクリプトのドキュメントは [https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script こちら] にあります。
Once installed, you can verify the SDKs available:
 
   
  +
たとえば、以下のコマンドで STS(Standard Term Support)チャンネルの最新版を {{ic|/usr/share/dotnet}} にインストールできます:
$ dotnet --list-sdks
 
2.2.108 [/usr/share/dotnet/sdk]
 
3.0.103 [/usr/share/dotnet/sdk]
 
$ dotnet --version
 
3.0.103
 
   
  +
# ./dotnet-install.sh --install-dir /usr/share/dotnet -channel STS -version latest
=== 複数のバージョンを AUR を使ってインストールする ===
 
   
  +
インストールをシミュレーションしたい場合は、{{ic|-Dryrun}} フラグを使用します。
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:
 
  +
  +
インストール後、利用可能な SDK を確認できます:
  +
  +
{{hc|$ dotnet --list-sdks|
  +
2.2.108 [/usr/share/dotnet/sdk]
  +
3.0.103 [/usr/share/dotnet/sdk]
  +
}}
  +
  +
{{hc|$ dotnet --version|
  +
3.0.103
  +
}}
  +
  +
=== 手動インストールしたバージョンのアンインストール ===
  +
  +
{{ic|dotnet-install.sh}} でインストールした古いバージョンを削除したい場合があります。[https://docs.microsoft.com/en-us/dotnet/core/additional-tools/uninstall-tool .NET Uninstall Tool] は現在 Linux をサポートしていないため、手動でアンインストールする必要があります。
  +
  +
{{hc|$ dotnet --list-sdks|
  +
5.0.100 [/usr/share/dotnet/sdk]
  +
5.0.102 [/usr/share/dotnet/sdk]
  +
}}
  +
  +
SDK の削除:
  +
  +
$ SDK_VERSION="5.0.100"
  +
$ DOTNET_UNINSTALL_PATH="/usr/share/dotnet"
  +
# rm -rf $DOTNET_UNINSTALL_PATH/sdk/$SDK_VERSION
  +
  +
{{ic|dotnet-install.sh}} を使用した場合、dotnet ホストや shared パッケージもインストールされているため、リリースに応じてこれらも追加で削除する必要があります。
  +
  +
.NET バージョン全体(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
  +
  +
=== AUR による複数バージョンのインストール ===
  +
  +
AUR にある一部の dotnet パッケージは共存できるように設計されています。コマンドラインツールを含むホストパッケージ({{aur|dotnet-host-bin}} または {{pkg|dotnet-host}})が 1 つ必要で、あとは任意の SDK やランタイム(各メジャーバージョンの最新版)を追加でインストールできます。以下は互換性のあるパッケージ一覧です:
   
 
* {{aur|dotnet-host-bin}}, {{aur|dotnet-runtime-bin}}, {{aur|aspnet-runtime-bin}}, {{aur|dotnet-sdk-bin}}
 
* {{aur|dotnet-host-bin}}, {{aur|dotnet-runtime-bin}}, {{aur|aspnet-runtime-bin}}, {{aur|dotnet-sdk-bin}}
* {{aur|dotnet-host-preview}}, {{aur|dotnet-runtime-preview}}, {{aur|aspnet-runtime-preview}}, {{aur|dotnet-sdk-preview}}
+
* {{aur|dotnet-host-preview-bin}}, {{aur|dotnet-runtime-preview-bin}}, {{aur|aspnet-runtime-preview-bin}}, {{aur|dotnet-sdk-preview-bin}}
* {{aur|dotnet-runtime-3.0}}, {{aur|aspnet-runtime-3.0}}, {{aur|dotnet-sdk-3.0}},
+
* {{aur|dotnet-runtime-8.0-bin}}, {{aur|aspnet-runtime-8.0-bin}}, {{aur|dotnet-sdk-8.0-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.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}}
 
* {{aur|dotnet-runtime-2.1}}, {{aur|aspnet-runtime-2.1}}, {{aur|dotnet-sdk-2.1}}
   
=== Install PowerShell Core ===
+
=== 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]
 
   
  +
PowerShell Core は "グローバル" ツールとしてもインストールできます:
# dotnet tool install --global PowerShell
 
  +
[https://devblogs.microsoft.com/powershell/introducing-powershell-as-net-global-tool/]
  +
[https://github.com]()
   
  +
== テレメトリ ==
to update to current version
 
# dotnet tool update --global PowerShell
 
   
  +
テレメトリはデフォルトで有効になっていますが、[[環境変数|環境変数の設定]]により無効にできます。{{ic|1=DOTNET_CLI_TELEMETRY_OPTOUT=1}}
== Telemetry ==
 
   
  +
== タブ補完 ==
Telemetry is enabled by default but can be disabled by [[環境変数|環境変数の設定]] {{ic|1=DOTNET_CLI_TELEMETRY_OPTOUT=1}}.
 
   
  +
{{ic|System.CommandLine.Parser}} を使用して引数を解析するすべての dotnet プログラムはオートコンプリートをサポートしています。これを有効にするには、[https://docs.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete#zsh それぞれのドキュメント]に記載されているように、{{ic|.bashrc}} / {{ic|.zshrc}} ファイルに数行追加するだけです。スタンドアロン・バイナリについては、 [https://github.com/dotnet/command-line-api/blob/main/docs/dotnet-suggest.md こちら]で説明されています。
== 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}}.
 
  +
  +
新しく作成したプロジェクトを実行しようとしたとき、次のエラーが発生した場合、GitHub のさまざまな問題の解決策に記載されているように、{{ic|DOTNET_ROOT}} 変数を設定する必要がなくなりました。Arch の dotnet パッケージは(3.1現在)、Microsoft が推奨する {{ic|/usr/share/dotnet}} にインストールされます。
   
 
{{hc|$ dotnet run|output=
 
{{hc|$ dotnet run|output=
72行目: 115行目:
 
}}
 
}}
   
  +
これは、Arch ではランタイムが別パッケージとして出荷されているために起こるものです。{{Pkg|aspnet-runtime}} パッケージがインストールされていることを確認する必要があります。
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 ===
+
=== "the required library libhostfxr.so could not be found" エラー ===
   
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's not, an error like this one could be observed: [https://github.com/dotnet/cli/issues/9114]
+
一部の dotnet SDK ツール(例えば、''libman'', ''dotnet-watch'' など)では、環境変数 {{ic|DOTNET_ROOT}} が事前に設定されていることを期待している場合があります。そうでない場合、このようなエラーが発生する可能性があります。[https://github.com/dotnet/cli/issues/9114]
   
 
A fatal error occurred, the required library libhostfxr.so could not be found.
 
A fatal error occurred, the required library libhostfxr.so could not be found.
82行目: 125行目:
 
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.
 
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:
+
回避策としては、手動でシェルに {{ic|DOTNET_ROOT}} をエクスポートします。
   
 
{{hc|1=~/.bashrc|2=
 
{{hc|1=~/.bashrc|2=
88行目: 131行目:
 
}}
 
}}
   
  +
=== 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. ===
=== SDK specified could not be found ===
 
   
  +
これはアップデート後に発生します。現在実行中のシェル/ログインセッションは、インストールされているものとは異なる dotnet SDK バージョンの環境変数が納められています。シェルを再起動するか、再度ログインすると直ります。
This is believed to caused by a conflict between the Mono and MSBuild SDK libs and the dotnet core ones. To fix this export the path manually in your shell (replacing the version number as necessary) e.g:
 
  +
  +
=== 指定された SDK が見つからない ===
  +
  +
これは Mono と MSBuild SDK ライブラリと dotnet のライブラリが競合していることが原因だと思われます。これを修正するには、シェルでパスを手動で export します(必要に応じてバージョン番号を置き換えてください)。
   
 
{{hc|1=~/.bashrc|2=
 
{{hc|1=~/.bashrc|2=
 
export MSBuildSDKsPath=$( echo /usr/share/dotnet/sdk/3.*/Sdks );
 
export MSBuildSDKsPath=$( echo /usr/share/dotnet/sdk/3.*/Sdks );
 
}}
 
}}
  +
  +
=== dotnet コマンドがインストールされたままになっている ===
  +
  +
インストールされたパッケージは dotnet-host をアンインストールしないので、{{Pkg|dotnet-host}} をアンインストールしてください。
   
 
== 参照 ==
 
== 参照 ==
  +
* [https://www.microsoft.com/net/core/platform .NET Core ホームページ]
 
  +
* [https://dotnet.microsoft.com/ .NET ホームページ]
 
* [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]
  +
  +
{{TranslationStatus|.NET|2023/2/6|758593}}

2025年7月31日 (木) 20:13時点における最新版

.NET(以前の名前は .NET Core) は Microsoft が提供する C#, Visual Basic, F# のための FOSS ソフトウェアフレームワークです。先行の .NET Framework と異なり、クロスプラットフォームでモジュール化され、近代的なアプリケーションに適した設計が行われています。

インストール

.NET マネージドアプリケーションを実行したいだけの場合は dotnet-runtime パッケージをインストールしてください。

.NET でアプリをビルドする場合は dotnet-sdk パッケージもインストールしてください。

最後に、ASP.NET Core を使用して動的な Web サイト、アプリケーション、およびサービスを構築するには、aspnet-runtimeをインストールします。

Microsoft は Visual Studio Code(同社の Electron ベースの IDE)を使用して .NET アプリを構築・デバッグすることを推奨しています。

ヒント: PATH~/.dotnet/tools を追加してください。追加しない場合は、 dotnet ツールはシェルから使うことができません。

.NET 6.0、7.0、8.0 を使用したい場合は、上記パッケージにそれぞれ "-6.0"、"-7.0"、"-8.0" をサフィックスとして付けてください(例:dotnet-runtime-8.0dotnet-sdk-8.0aspnet-runtime-8.0

バージョンの違い

.NET SDK は複数のバージョン体系で公開されています。1xx バージョンの SDK のみがソースからビルド可能で、公式リポジトリで提供されます。それ以外のバージョンが必要な場合は、AUR にある *-bin パッケージを使用する必要があります。

複数バージョンの手動インストール

複数の .NET SDK やランタイムを共存させるには、.NET Foundation が提供する dotnet-install.sh スクリプトを使用します。スクリプトのドキュメントは こちら にあります。

たとえば、以下のコマンドで STS(Standard Term Support)チャンネルの最新版を /usr/share/dotnet にインストールできます:

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

インストールをシミュレーションしたい場合は、-Dryrun フラグを使用します。

インストール後、利用可能な SDK を確認できます:

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

手動インストールしたバージョンのアンインストール

dotnet-install.sh でインストールした古いバージョンを削除したい場合があります。.NET Uninstall Tool は現在 Linux をサポートしていないため、手動でアンインストールする必要があります。

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

SDK の削除:

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

dotnet-install.sh を使用した場合、dotnet ホストや shared パッケージもインストールされているため、リリースに応じてこれらも追加で削除する必要があります。

.NET バージョン全体(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

AUR による複数バージョンのインストール

AUR にある一部の dotnet パッケージは共存できるように設計されています。コマンドラインツールを含むホストパッケージ(dotnet-host-binAUR または dotnet-host)が 1 つ必要で、あとは任意の SDK やランタイム(各メジャーバージョンの最新版)を追加でインストールできます。以下は互換性のあるパッケージ一覧です:

PowerShell Core のインストール

PowerShell Core は "グローバル" ツールとしてもインストールできます: [1] [2]()

テレメトリ

テレメトリはデフォルトで有効になっていますが、環境変数の設定により無効にできます。DOTNET_CLI_TELEMETRY_OPTOUT=1

タブ補完

System.CommandLine.Parser を使用して引数を解析するすべての dotnet プログラムはオートコンプリートをサポートしています。これを有効にするには、それぞれのドキュメントに記載されているように、.bashrc / .zshrc ファイルに数行追加するだけです。スタンドアロン・バイナリについては、 こちらで説明されています。

トラブルシューティング

対応するフレームワークのバージョンを見つけることができませんでした

新しく作成したプロジェクトを実行しようとしたとき、次のエラーが発生した場合、GitHub のさまざまな問題の解決策に記載されているように、DOTNET_ROOT 変数を設定する必要がなくなりました。Arch の dotnet パッケージは(3.1現在)、Microsoft が推奨する /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

これは、Arch ではランタイムが別パッケージとして出荷されているために起こるものです。aspnet-runtime パッケージがインストールされていることを確認する必要があります。

"the required library libhostfxr.so could not be found" エラー

一部の dotnet SDK ツール(例えば、libman, dotnet-watch など)では、環境変数 DOTNET_ROOT が事前に設定されていることを期待している場合があります。そうでない場合、このようなエラーが発生する可能性があります。[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.

回避策としては、手動でシェルに DOTNET_ROOT をエクスポートします。

~/.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.

これはアップデート後に発生します。現在実行中のシェル/ログインセッションは、インストールされているものとは異なる dotnet SDK バージョンの環境変数が納められています。シェルを再起動するか、再度ログインすると直ります。

指定された SDK が見つからない

これは Mono と MSBuild SDK ライブラリと dotnet のライブラリが競合していることが原因だと思われます。これを修正するには、シェルでパスを手動で export します(必要に応じてバージョン番号を置き換えてください)。

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

dotnet コマンドがインストールされたままになっている

インストールされたパッケージは dotnet-host をアンインストールしないので、dotnet-host をアンインストールしてください。

参照

翻訳ステータス: このページは en:.NET の翻訳バージョンです。最後の翻訳日は 2023/2/6 です。もし英語版に 変更 があれば、翻訳の同期を手伝うことができます。