「.NET」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(→‎インストール: 節を追加(英語版より))
(他言語リンクを追加。飜訳状況を修正)
 
(2人の利用者による、間の38版が非表示)
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 は .NET Core アプリをビルド・デバッグするときは [[Electron]] ベースのオープンソース IDE である [[Visual Studio Code]] を使うことを推奨しています。
   
{{Tip|{{ic|PATH}} に {{ic|~/.dotnet/tools}} を追加してください。追加しない場合は、 dotnetツールはシェルから使うことができません。}}
+
{{Tip|{{ic|PATH}} に {{ic|~/.dotnet/tools}} を追加してください。追加しない場合は、 dotnet ツールはシェルから使うことができません。}}
   
  +
=== 手動による複数バージョンのインストール ===
=== Install multiple versions manually ===
 
   
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].
+
.NET Foundation が提供する [https://dot.net/v1/dotnet-install.sh dotnet-install.sh] スクリプトを使用して、.NET SDK またはランタイムの複数のバージョンをインストールできます。スクリプトのドキュメントは[https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script ここ]にあります。
   
  +
例えば、以下のコマンドは、{{ic|/usr/share/dotnet}} の "STS"(Standard Term Support) チャネルにある最新バージョンをインストールします:
For instance, this command would install the latest version found in the "current" channel in {{ic|/usr/share/dotnet}}:
 
   
# ./dotnet-install.sh --install-dir /usr/share/dotnet -channel Current -version latest
+
# ./dotnet-install.sh --install-dir /usr/share/dotnet -channel STS -version latest
   
  +
{{ic|-Dryrun}} を使用して、最初にインストールをシミュレートすることをお勧めします。
You may want to simulate the installation first by using the {{ic|-Dryrun}} flag.
 
   
  +
インストールしたら、利用可能な SDK を確認できます:
Once installed, you can verify the SDKs available:
 
   
$ dotnet --list-sdks
+
{{hc|$ dotnet --list-sdks|
2.2.108 [/usr/share/dotnet/sdk]
+
2.2.108 [/usr/share/dotnet/sdk]
3.0.103 [/usr/share/dotnet/sdk]
+
3.0.103 [/usr/share/dotnet/sdk]
  +
}}
$ dotnet --version
 
3.0.103
 
   
  +
{{hc|$ dotnet --version|
=== Install multiple versions via AUR ===
 
  +
3.0.103
  +
}}
   
  +
=== 手動でインストールしたバージョンをアンインストールする ===
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:
 
  +
  +
{{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 ホストと共有パッケージもインストールされますが、リリースによっては追加で削除しなければならない場合もあります。
  +
  +
.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}}) は一つだけが必要で、その隣に利用可能な 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-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 を「グローバル」ツールとしてインストールすることもできます[https://devblogs.microsoft.com/powershell/introducing-powershell-as-net-global-tool/] [https://github.com/powershell/powershell]。
   
 
# dotnet tool install --global PowerShell
 
# dotnet tool install --global PowerShell
   
  +
現在のバージョンを更新するには、
to update to current version
 
  +
 
# dotnet tool update --global PowerShell
 
# dotnet tool update --global PowerShell
  +
  +
== テレメトリ ==
  +
  +
テレメトリはデフォルトで有効になっていますが、[[環境変数|環境変数の設定]]により無効にできます。{{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 こちら]で説明されています。
  +
  +
== トラブルシューティング ==
  +
  +
=== 対応するフレームワークのバージョンを見つけることができませんでした ===
  +
  +
新しく作成したプロジェクトを実行しようとしたとき、次のエラーが発生した場合、GitHub のさまざまな問題の解決策に記載されているように、{{ic|DOTNET_ROOT}} 変数を設定する必要がなくなりました。Arch の dotnet パッケージは(3.1現在)、Microsoft が推奨する {{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
  +
}}
  +
  +
これは、Arch ではランタイムが別パッケージとして出荷されているために起こるものです。{{Pkg|aspnet-runtime}} パッケージがインストールされていることを確認する必要があります。
  +
  +
=== "the required library libhostfxr.so could not be found" エラー ===
  +
  +
一部の 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.
  +
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.
  +
  +
回避策としては、手動でシェルに {{ic|DOTNET_ROOT}} をエクスポートします。
  +
  +
{{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. ===
  +
  +
これはアップデート後に発生します。現在実行中のシェル/ログインセッションは、インストールされているものとは異なる dotnet SDK バージョンの環境変数が納められています。シェルを再起動するか、再度ログインすると直ります。
  +
  +
=== 指定された SDK が見つからない ===
  +
  +
これは Mono と MSBuild SDK ライブラリと dotnet のライブラリが競合していることが原因だと思われます。これを修正するには、シェルでパスを手動で export します(必要に応じてバージョン番号を置き換えてください)。
  +
  +
{{hc|1=~/.bashrc|2=
  +
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}}

2023年2月6日 (月) 14:25時点における最新版

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

インストール

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

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

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

Microsoft は .NET Core アプリをビルド・デバッグするときは Electron ベースのオープンソース IDE である Visual Studio Code を使うことを推奨しています。

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

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

.NET Foundation が提供する dotnet-install.sh スクリプトを使用して、.NET SDK またはランタイムの複数のバージョンをインストールできます。スクリプトのドキュメントはここにあります。

例えば、以下のコマンドは、/usr/share/dotnet の "STS"(Standard Term Support) チャネルにある最新バージョンをインストールします:

# ./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 ホストと共有パッケージもインストールされますが、リリースによっては追加で削除しなければならない場合もあります。

.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) は一つだけが必要で、その隣に利用可能な SDK とランタイム(すべてのメジャーバージョンの最新パッケージ)をインストールできます。互換性のあるパッケージのリストは以下の通りです。

PowerShell Core のインストール

PowerShell Core を「グローバル」ツールとしてインストールすることもできます[1] [2]

# dotnet tool install --global PowerShell

現在のバージョンを更新するには、

# dotnet tool update --global PowerShell

テレメトリ

テレメトリはデフォルトで有効になっていますが、環境変数の設定により無効にできます。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 です。もし英語版に 変更 があれば、翻訳の同期を手伝うことができます。