dotnet coreコマンド詳細

6860 ワード

このブログではdotnetという不思議なコマンドについて説明します.dotnet、dotnet new、dotnet restore、dotnet build、dotnet test、dotnet run、dotnet pack、dotnet publishというコマンドの使い方を順に簡単に紹介し、プレゼンテーションします.

dotnet


dotnetコマンドは、主にプラットフォーム、バージョン番号などの基本的な情報を表示するために使用されます.よく使われるパラメータは-version、-info、-helpです.次は順次実行して出力を見てみましょう.
dotnet –version 1.0.0-preview2-003121 dotnet –info .NET Command Line Tools (1.0.0-preview2-003121)
Product Information: Version: 1.0.0-preview2-003121 Commit SHA-1 hash: 1e9d529bc5
Runtime Environment: OS Name: Mac OS X OS Version: 10.11 OS Platform: Darwin RID: osx.10.11-x64 dotnet –help .NET Command Line Tools (1.0.0-preview2-003121) Usage: dotnet [host-options] [command] [arguments] [common-options]
Arguments: [command] The command to execute [arguments] Arguments to pass to the command [host-options] Options specific to dotnet (host) [common-options] Options common to all commands
Common options: -v|–verbose Enable verbose output -h|–help Show help
Host options (passed before the command): -v|–verbose Enable verbose output –version Display .NET CLI Version Number –info Display .NET CLI Info
Common Commands: new Initialize a basic .NET project restore Restore dependencies specified in the .NET project build Builds a .NET project publish Publishes a .NET project for deployment (including the runtime) run Compiles and immediately executes a .NET project test Runs unit tests using the test runner specified in the project pack Creates a NuGet package

dotnet new


dotnet newコマンドは、1つを作成するために使用されます.Netcoreプロジェクト.このコマンドには、-t(または-type)と-l(または-lang)の2つのオプションがあり、プロジェクトタイプとプログラミング言語を指定します.
-l,–lang[C#|F#]-lのデフォルト値はc#ですが、f#に設定することもできます.VBならすぐにサポートできるはずです.
-t,–type[console|web|lib|xunittest]-tのデフォルト値はconcole、コンソールプロジェクトです.他のいくつかのパラメータは、Webプロジェクト、クラスライブラリプロジェクト、テストプロジェクトを表します.たとえば、dotnet newコマンドはコンソールプロジェクトを作成し、dotnet new-t webはwebプロジェクト(asp.net mvc)を作成します.

dotnet restore


dotnet restore[–source][–packages][–disable-parallel][–fallbacksource][–configfile][–verbosity][]dotnet restoreコマンドはNuGetを介してprojectで定義をダウンロードする.jsonファイルの依存は、ユーザーディレクトリの下に置く.nuget/packagesフォルダにあります.デフォルトでは、ダウンロード依存構築のプロセスは並列に行われます.–packagesオプションは、ダウンロードしたコンポーネントを格納する場所を指定できます.デフォルトはユーザーディレクトリの下です.nuget/packagesフォルダ.–disable-parallelオプションは、パラレルダウンロードを無効にします.–configfileオプションは、どのNuGetを使用するかを指定するために使用されます.configファイル.dotnet restoreコマンドの実行が完了するとprojectが生成されます.lock.jsonファイル.

dotnet build


dotnet build[–output][–build-base-path][–framework][–configuration][–runtime][–version-suffix][–build-profile][–no-incremental][–no-dependencies][]dotnet buildコマンドは、プロジェクト内のすべてのソースファイルと依存するコンポーネントをバイナリdllファイルにコンパイルします.このコマンドはprojectを読み込みます.lock.json、プロジェクトでファイルが見つからない場合はdotnet restoreコマンドを先に実行する必要があります.dotnet buildコマンドを実行するとbin/Debug/netcoreapp 1になります.0フォルダで生成する.dllファイルと.pbdファイルなど、例えば:
bash-3.2$ ls -al bin/Debug/netcoreapp1.0/ total 80 drwxr-xr-x 11 jingjing staff 374 9 6 22:08 . drwxr-xr-x 6 jingjing staff 204 9 6 21:52 .. -rw-r–r–@ 1 jingjing staff 6148 9 6 23:13 .DS_Store -rwxr–r– 1 jingjing staff 1636 9 5 22:38 app.deps.json -rwxr–r– 1 jingjing staff 4608 9 5 22:38 app.dll -rwxr–r– 1 jingjing staff 496 9 5 22:38 app.pdb -rwxr–r– 1 jingjing staff 107 9 5 22:38 app.runtimeconfig.dev.json -rwxr–r– 1 jingjing staff 118 9 5 22:38 app.runtimeconfig.json -rwxr–r– 1 jingjing staff 3584 9 5 22:05 library.dll -rwxr–r– 1 jingjing staff 452 9 5 22:05 library.pdb drwxr-xr-x 10 jingjing staff 340 9 6 22:08 publish

dotnet test


dotnet test[–configuration][–output][–build-base-path][–framework][–runtime][–no-build][–parentProcessId][–port][]dotnet testコマンドは、nunitやxunitなどのユニットテストフレームワークと対応するユニットテストランナに依存するユニットテストランナを実行するために使用されます.jsonファイルではtestRunnerノードで指定します.以下に、ユニットテストフレームワークとしてxunitを用いる項目のprojectを示す.jsonファイル
{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable"
  },
  "dependencies": {
    "System.Runtime.Serialization.Primitives": "4.1.1",
    "xunit": "2.1.0",
    "dotnet-test-xunit": "1.0.0-rc2-192208-24"
  },
  "testRunner": "xunit",
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0" }
      },
      "imports": [
        "dotnet5.4",
        "portable-net451+win8"
      ]
    }
  }
}

ここで、「testRunner」:「xunit」は、必要なユニットテストランナを示します.

dotnet run


dotnet run[–framework][–configuration][–project][–help][-]dotnet runコマンドは、コードを実行するのに便利なコマンドです.コードをコンパイルし、情報を出力し、コードを実行します.

dotnet pack


dotnet pack[-output][-no-build][-build-base-path][-configuration][-version-suffix][]dotnet packコマンドコードをコンパイルしてNuGetパッケージを生成する、具体的にはbinDebugディレクトリの下で1つ生成する.nupkgファイルと1つ.symbols.nupkgファイル.

dotnet publish


dotnet publish[–framework][–runtime][–build-base-path][–output][–version-suffix][–configuration][]dotnet publishコマンドはコードをコンパイルし、projectを読み込む.jsonファイルで定義されたすべての依存コンポーネントは、最後にフォルダに出力されます.生成されたファイルはデフォルトでbinDebugetcoreapp 1に出力されます.0publishでは、-oまたは-outputオプションで出力位置を変更できます.コードをパブリッシュする必要がある場合は、コマンドの出力ファイルが必要なすべてのファイルになります.