.NET CLI の概要.NET CLI overview
この記事の対象: ✔️ .NET Core 2.1 SDK 以降のバージョンThis article applies to: ✔️ .NET Core 2.1 SDK and later versions
.NET コマンド ライン インターフェイス (CLI) は、.NET アプリケーションを開発、ビルド、実行、発行するためのクロスプラットフォーム ツールチェーンです。The .NET command-line interface (CLI) is a cross-platform toolchain for developing, building, running, and publishing .NET applications.
.NET CLI は、.NET SDK に含まれています。The .NET CLI is included with the .NET SDK. .NET SDK をインストールする方法については、.NET のインストールに関する記事をご覧ください。To learn how to install the .NET SDK, see Install .NET Core.
CLI コマンドCLI commands
既定では、次のコマンドがインストールされます。The following commands are installed by default:
基本的なコマンドBasic commands
プロジェクトの変更コマンドProject modification commands
高度なコマンドAdvanced commands
ツール管理コマンドTool management commands
tool install
tool list
tool update
tool restore
.NET Core SDK 3.0 以降で利用できます。tool restore
Available since .NET Core SDK 3.0.tool run
.NET Core SDK 3.0 以降で利用できます。tool run
Available since .NET Core SDK 3.0.tool uninstall
ツールは、NuGet パッケージからインストールされ、コマンド プロンプトから呼び出されるコンソール アプリケーションです。Tools are console applications that are installed from NuGet packages and are invoked from the command prompt. ツールは自分で作成することも、サードパーティによって作成されたツールをインストールすることもできます。You can write tools yourself or install tools written by third parties. ツールは、グローバル ツール、ツールパス ツール、およびローカル ツールとも呼ばれます。Tools are also known as global tools, tool-path tools, and local tools. 詳細については、.NET ツールの概要に関するページを参照してください。For more information, see .NET tools overview.
コマンド構造Command structure
CLI コマンド構造は、ドライバー ("dotnet") とコマンド、また場合によってはコマンドの引数とオプションで構成されます。CLI command structure consists of the driver ("dotnet"), the command, and possibly command arguments and options. my_app という名前のディレクトリから実行する場合、次のコマンドで示されているように、新しいコンソール アプリの作成やコマンド ラインからの実行など、ほとんどの CLI 操作でこのパターンが見られます。You see this pattern in most CLI operations, such as creating a new console app and running it from the command line as the following commands show when executed from a directory named my_app:
dotnet new console
dotnet build --output /build_output
dotnet /build_output/my_app.dll
ドライバーDriver
ドライバーは dotnet という名前で、2 つの役割 (フレームワークに依存するアプリの実行と、コマンドの実行) があります。The driver is named dotnet and has two responsibilities, either running a framework-dependent app or executing a command.
フレームワークに依存するアプリを実行するには、dotnet /path/to/my_app.dll
など、ドライバーの後にアプリを指定します。To run a framework-dependent app, specify the app after the driver, for example, dotnet /path/to/my_app.dll
. アプリの DLL が存在するフォルダーからコマンドを実行する場合は、dotnet my_app.dll
を実行するだけです。When executing the command from the folder where the app's DLL resides, simply execute dotnet my_app.dll
. .NET ランタイムの特定のバージョンを使用する場合は、--fx-version <VERSION>
オプションを使用してください (「dotnet コマンド」リファレンスを参照)。If you want to use a specific version of the .NET Runtime, use the --fx-version <VERSION>
option (see the dotnet command reference).
ドライバーにコマンドを指定すると、dotnet.exe
は CLI コマンドの実行プロセスを開始します。When you supply a command to the driver, dotnet.exe
starts the CLI command execution process. 次に例を示します。For example:
dotnet build
最初に、ドライバーは使用する SDK のバージョンを決定します。First, the driver determines the version of the SDK to use. global.json ファイルがない場合は、利用可能な SDK の最新バージョンを使用します。If there is no global.json file, the latest version of the SDK available is used. コンピューターで最新のプレビューまたは安定したバージョンになります。This might be either a preview or stable version, depending on what is latest on the machine. SDK バージョンが決定されたら、コマンドを実行します。Once the SDK version is determined, it executes the command.
コマンドCommand
コマンドは、アクションを実行します。The command performs an action. たとえば、dotnet build
はコードをビルドします。For example, dotnet build
builds code. dotnet publish
はコードを発行します。dotnet publish
publishes code. コマンドは、dotnet {command}
規則を使用してコンソール アプリケーションとして実装されます。The commands are implemented as a console application using a dotnet {command}
convention.
引数Arguments
コマンド ラインで渡す引数は、呼び出されたコマンドへの引数です。The arguments you pass on the command line are the arguments to the command invoked. たとえば、dotnet publish my_app.csproj
を実行した場合、my_app.csproj
引数は、発行するプロジェクトを示し、publish
コマンドに渡されます。For example, when you execute dotnet publish my_app.csproj
, the my_app.csproj
argument indicates the project to publish and is passed to the publish
command.
オプションOptions
コマンド ラインで渡すオプションは、呼び出されたコマンドへのオプションです。The options you pass on the command line are the options to the command invoked. たとえば、dotnet publish --output /build_output
を実行した場合、--output
オプションとその値は publish
コマンドに渡されます。For example, when you execute dotnet publish --output /build_output
, the --output
option and its value are passed to the publish
command.