Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

.NET用パッケージマネージャNuGetでアレコレ拡張する

NuGetはWikipediaによると

NuGetとは.NET Frameworkに対応するフリー・アンド・オープンソースのパッケージマネージャである

とのこと。
brewやapt-get、chocolatyみたいなものですね。
提供されているパッケージ類も豊富でテストスイートからフロントエンド、DB系まで色々9000個程。
NuGet Gallery | Packages

Windows版なら、VisualStudio自体にも内蔵されています。
我々*NIX使い向けにはCLIも提供されていますのでソイツを使いましょう。
github.com
無事にブチ込んでから環境変数を再読込すると、以下のような感じで出てきます。

$ nuget 
NuGet Version: 4.3.0.4406
usage: NuGet <command> [args] [options] 
Type 'NuGet help <command>' for help on a specific command.

Available commands:

 add         Adds the given package to a hierarchical source. http sources are not supp
             orted. For more info, goto https://docs.nuget.org/consume/command-line-ref
             erence#add-command.

 config      NuGet 構成値を取得または設定します。

 delete      サーバーからパッケージを削除します。

 help (?)    全般的なヘルプ情報と他のコマンドに関するヘルプ情報を表示します。

 init        Adds all the packages from the <srcPackageSourcePath> to the hierarchical 
             <destPackageSourcePath>. http feeds are not supported. For more info, goto
             https://docs.nuget.org/consume/command-line-reference#init-command.

 install     指定されたソースを使用してパッケージをインストールします。ソースが指定されていない場合、NuGet 構成ファイルに定義されているすべてのソースが使用
             されます。構成ファイルにソースが指定されていない場合、既定の NuGet フィードが使用されます。

 list        指定したソースのパッケージ一覧を表示します。ソースが指定されていない場合、%AppData%\NuGet\NuGet.config に定義されている
             すべてのソースが使用されます。NuGet.config にソースが指定されていない場合、既定の NuGet フィードが使用されます。

 locals      Clears or lists local NuGet resources such as http requests cache, temp ca
             che or machine-wide global packages folder.

 pack        指定された nuspec または project ファイルに基づいて、NuGet パッケージを作成します。

 push        サーバーにパッケージをプッシュして、公開します。
             NuGet の既定の構成を取得するには、%AppData%\NuGet\NuGet.config を読み込み、ドライブのルートから現在のディレクトリ
             の間にあるすべての nuget.config または .nuget\nuget.config を読み込みます。

 restore     NuGet パッケージを復元します。

 setApiKey   指定されたサーバーの URL の API キーを保存します。URL が指定されていない場合、NuGet ギャラリーの API キーが保存されます。

 sources     %AppData%\NuGet\NuGet.config に指定されたソースの一覧を管理できます

 spec        新しいパッケージの nuspec を生成します。このコマンドをプロジェクト ファイル (.csproj, .vbproj, .fsproj) と同じ
             フォルダーで実行する場合、トークン化された nuspec ファイルが作成されます。

 update      パッケージを利用可能な最新バージョンに更新します。このコマンドで、NuGet.exe も更新されます。

詳細については、http://docs.nuget.org/docs/reference/command-line-reference を参照してください

つかいかた

たとえば、Office2007以降で採用されたOpen XMLをよろしく使うClosed XMLだと
NuGet Gallery | ClosedXML 0.90.0
これだけ。

$ nuget install ClosedXML
Feeds used:
  https://api.nuget.org/v3/index.json

  GET https://api.nuget.org/v3/registration3-gz-semver2/closedxml/index.json
  OK https://api.nuget.org/v3/registration3-gz-semver2/closedxml/index.json 1041ms


Attempting to gather dependency information for package 'ClosedXML.0.90.0' with respect to project '/Users/shuzo_kino/csharp', targeting 'Any,Version=v0.0'
Gathering dependency information took 1.68 min
Attempting to resolve dependencies for package 'ClosedXML.0.90.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'ClosedXML.0.90.0'
Resolved actions to install package 'ClosedXML.0.90.0'
Retrieving package 'ClosedXML 0.90.0' from 'nuget.org'.
Retrieving package 'DocumentFormat.OpenXml 2.7.2' from 'nuget.org'.
Retrieving package 'FastMember.Signed 1.1.0' from 'nuget.org'.
Retrieving package 'System.IO.FileSystem.Primitives 4.0.1' from 'nuget.org'.
Retrieving package 'System.IO.Packaging 4.0.0' from 'nuget.org'.
  GET https://api.nuget.org/v3-flatcontainer/closedxml/0.90.0/closedxml.0.90.0.nupkg
  OK https://api.nuget.org/v3-flatcontainer/closedxml/0.90.0/closedxml.0.90.0.nupkg 1042ms
Installing ClosedXML 0.90.0.
  GET https://api.nuget.org/v3-flatcontainer/fastmember.signed/1.1.0/fastmember.signed.1.1.0.nupkg
  OK https://api.nuget.org/v3-flatcontainer/fastmember.signed/1.1.0/fastmember.signed.1.1.0.nupkg 935ms
Installing FastMember.Signed 1.1.0.
  GET https://api.nuget.org/v3-flatcontainer/documentformat.openxml/2.7.2/documentformat.openxml.2.7.2.nupkg
Adding package 'FastMember.Signed.1.1.0' to folder '/Users/shuzo_kino/csharp'
Added package 'FastMember.Signed.1.1.0' to folder '/Users/shuzo_kino/csharp'
Successfully installed 'FastMember.Signed 1.1.0' to /Users/shuzo_kino/csharp
  OK https://api.nuget.org/v3-flatcontainer/documentformat.openxml/2.7.2/documentformat.openxml.2.7.2.nupkg 1155ms
Installing DocumentFormat.OpenXml 2.7.2.
  GET https://api.nuget.org/v3-flatcontainer/system.io.packaging/4.0.0/system.io.packaging.4.0.0.nupkg
  OK https://api.nuget.org/v3-flatcontainer/system.io.packaging/4.0.0/system.io.packaging.4.0.0.nupkg 996ms
Installing System.IO.Packaging 4.0.0.
  GET https://api.nuget.org/v3-flatcontainer/system.io.filesystem.primitives/4.0.1/system.io.filesystem.primitives.4.0.1.nupkg
  OK https://api.nuget.org/v3-flatcontainer/system.io.filesystem.primitives/4.0.1/system.io.filesystem.primitives.4.0.1.nupkg 880ms
Installing System.IO.FileSystem.Primitives 4.0.1.
Adding package 'System.IO.FileSystem.Primitives.4.0.1' to folder '/Users/shuzo_kino/csharp'
Added package 'System.IO.FileSystem.Primitives.4.0.1' to folder '/Users/shuzo_kino/csharp'
Successfully installed 'System.IO.FileSystem.Primitives 4.0.1' to /Users/shuzo_kino/csharp
Adding package 'System.IO.Packaging.4.0.0' to folder '/Users/shuzo_kino/csharp'
Added package 'System.IO.Packaging.4.0.0' to folder '/Users/shuzo_kino/csharp'
Successfully installed 'System.IO.Packaging 4.0.0' to /Users/shuzo_kino/csharp
Adding package 'DocumentFormat.OpenXml.2.7.2' to folder '/Users/shuzo_kino/csharp'
Added package 'DocumentFormat.OpenXml.2.7.2' to folder '/Users/shuzo_kino/csharp'
Successfully installed 'DocumentFormat.OpenXml 2.7.2' to /Users/shuzo_kino/csharp
Adding package 'ClosedXML.0.90.0' to folder '/Users/shuzo_kino/csharp'
Added package 'ClosedXML.0.90.0' to folder '/Users/shuzo_kino/csharp'
Successfully installed 'ClosedXML 0.90.0' to /Users/shuzo_kino/csharp
Executing nuget actions took 13.18 sec

参考もと

docs.microsoft.com