「.NET」の版間の差分
Kusanaginoturugi (トーク | 投稿記録) →テレメトリ: == Tab-Completion == を追加 |
Kusanaginoturugi (トーク | 投稿記録) 他言語リンクを追加。飜訳状況を修正 |
||
| (同じ利用者による、間の23版が非表示) | |||
| 1行目: | 1行目: | ||
[[Category:フレームワーク]] |
[[Category:フレームワーク]] |
||
[[en:.NET |
[[en:.NET]] |
||
[[ |
[[zh-hans:.NET]] |
||
[[pt:.NET Core]] |
|||
[[zh-hans:.NET Core]] |
|||
'''.NET'''(以前の名前は .NET Core) は Microsoft が提供する C#, Visual Basic, F# のための FOSS ソフトウェアフレームワークです。先行の .NET Framework と異なり、クロスプラットフォームでモジュール化され、近代的なアプリケーションに適した設計が行われています。 |
'''.NET'''(以前の名前は .NET Core) は Microsoft が提供する C#, Visual Basic, F# のための FOSS ソフトウェアフレームワークです。先行の .NET Framework と異なり、クロスプラットフォームでモジュール化され、近代的なアプリケーションに適した設計が行われています。 |
||
== インストール == |
== インストール == |
||
.NET |
.NET マネージドアプリケーションを実行したいだけの場合は {{Pkg|dotnet-runtime}} パッケージを[[インストール]]してください。 |
||
.NET |
.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 ツールはシェルから使うことができません。}} |
||
=== 手動による複数バージョンのインストール === |
=== 手動による複数バージョンのインストール === |
||
.NET Foundation が提供する [https://dot.net/v1/dotnet-install.sh dotnet-install.sh] スクリプトを使用して、.NET |
.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}} の " |
例えば、以下のコマンドは、{{ic|/usr/share/dotnet}} の "STS"(Standard Term Support) チャネルにある最新バージョンをインストールします: |
||
# ./dotnet-install.sh --install-dir /usr/share/dotnet -channel |
# ./dotnet-install.sh --install-dir /usr/share/dotnet -channel STS -version latest |
||
{{ic|-Dryrun}} を使用して、最初にインストールをシミュレートすることをお勧めします。 |
{{ic|-Dryrun}} を使用して、最初にインストールをシミュレートすることをお勧めします。 |
||
| 28行目: | 28行目: | ||
インストールしたら、利用可能な SDK を確認できます: |
インストールしたら、利用可能な SDK を確認できます: |
||
{{hc|$ dotnet --list-sdks| |
|||
2.2.108 [/usr/share/dotnet/sdk] |
|||
3.0.103 [/usr/share/dotnet/sdk] |
|||
}} |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
}} |
|||
=== 手動でインストールしたバージョンをアンインストールする === |
=== 手動でインストールしたバージョンをアンインストールする === |
||
| 64行目: | 67行目: | ||
=== AURによる複数バージョンのインストール === |
=== AURによる複数バージョンのインストール === |
||
AUR dotnet パッケージのいくつかは、並行してインストールするように作られています。コマンドラインツールを含むホストパッケージ({{aur|dotnet-host-bin}} または {{pkg|dotnet-host}}) は一つだけが必要で、その隣に利用可能な SDK とランタイム(すべてのメジャーバージョンの最新パッケージ)をインストールできます。互換性のあるパッケージのリストは以下の通りです。 |
|||
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-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}} |
||
| 73行目: | 76行目: | ||
=== PowerShell Core のインストール === |
=== PowerShell Core のインストール === |
||
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 |
||
| 84行目: | 89行目: | ||
テレメトリはデフォルトで有効になっていますが、[[環境変数|環境変数の設定]]により無効にできます。{{ic|1=DOTNET_CLI_TELEMETRY_OPTOUT=1}} |
テレメトリはデフォルトで有効になっていますが、[[環境変数|環境変数の設定]]により無効にできます。{{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 こちら]で説明されています。 |
|||
== トラブルシューティング == |
== トラブルシューティング == |
||
=== 対応するフレームワークのバージョンを見つけることができませんでした === |
|||
=== It was not possible to find any compatible framework version === |
|||
新しく作成したプロジェクトを実行しようとしたとき、次のエラーが発生した場合、GitHub のさまざまな問題の解決策に記載されているように、{{ic|DOTNET_ROOT}} 変数を設定する必要がなくなりました。Arch の dotnet パッケージは(3.1現在)、Microsoft が推奨する {{ic|/usr/share/dotnet}} にインストールされます。 |
|||
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= |
{{hc|$ dotnet run|output= |
||
| 106行目: | 111行目: | ||
}} |
}} |
||
これは、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" |
=== "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. |
A fatal error occurred, the required library libhostfxr.so could not be found. |
||
| 116行目: | 121行目: | ||
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. |
||
回避策としては、手動でシェルに {{ic|DOTNET_ROOT}} をエクスポートします。 |
|||
{{hc|1=~/.bashrc|2= |
{{hc|1=~/.bashrc|2= |
||
| 122行目: | 127行目: | ||
}} |
}} |
||
=== 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:// |
* [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 とランタイム(すべてのメジャーバージョンの最新パッケージ)をインストールできます。互換性のあるパッケージのリストは以下の通りです。
- dotnet-host-binAUR, dotnet-runtime-binAUR, aspnet-runtime-binAUR, dotnet-sdk-binAUR
- dotnet-host-preview-binAUR, dotnet-runtime-preview-binAUR, aspnet-runtime-preview-binAUR, dotnet-sdk-preview-binAUR
- dotnet-runtime-3.0AUR, aspnet-runtime-3.0AUR, dotnet-sdk-3.0AUR,
- dotnet-runtime-2.2AUR, aspnet-runtime-2.2AUR, dotnet-sdk-2.2AUR, dotnet-sdk-2.2-vs2017AUR
- dotnet-runtime-2.1AUR, aspnet-runtime-2.1AUR, dotnet-sdk-2.1AUR
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 をアンインストールしてください。