ぜんぶなんとかなる

ふしみの雑文

NuGet で package を公開する

NuGet という、Microsoft 謹製のパッケージマネージャが存在する。Visual Studio に付属しており、NuGet から様々なモジュールをインストールできる。依存関係もうまく解決してくれる。

NuGet の package は、NuGet.exe というバイナリを使って作成・公開できる。msdn のサイトで詳しい解説がある。

http://msdn.microsoft.com/ja-jp/magazine/hh547106.aspx http://msdn.microsoft.com/ja-jp/magazine/hh708753.aspx

実際には、JavaScript のライブラリなど、上記の資料が役に立たない場合も多い。「NuGet Package Explorer」という便利なツールが CodePlex 上で公開されているのでこれを使う。

NuGet Package Explorer

このページ を参考にしながら、適宜スクショをパクりつつ、NPE を使って NuGet のパッケージを Publish するところまでやってみる。

Nuget Package Explorer

Create New Package を選ぶ。

Edit から Edit Package Metadata

上記のページを参考にいろいろ入れる

Id (Mandatory)– This is the name by which devs will be installing it. So to install the above package you have to say Install-package Google.DiffMatchPatch.Js No spaces and special characters allowed in this field.

Version (Mandatory) – If this is your library, following the naming conventions you usually do and map this value to the version of code you are going to package.

Title – A descriptive name of the package

Authors (Mandatory) – This is the package Author usually. Since I am packaging on Neil’s behalf I have made it clear.

Owner – Owner of the code

Icon – If you have a nice icon available for your package the url that goes here

Project Url – URL where the project is hosted or where more information can be obtained about the project.

Requires License Agreement – If you wish explicit license agreement check this. This will publish a license warning when the package is deployed from the console.

Summary – A summary of what the package is about.

Description (Mandatory) – Detailed description of what the package is about. Release Notes – If any.

Version が同じパッケージは再度アップロードできない。最初の数回の publish は、ディレクトリ構成などを変更しながら様子を見ようと思うなら、ここを 1.0.0 などにすべきではない。最終的に公開したいバージョン番号より小さな数字で試す。

他のパッケージへの依存関係があれば、ここで登録しておく。

パッケージの中に contents フォルダを追加する。contents フォルダの中に、実際のソースコードなどを詰めることになる。

フォルダの中には、エクスプローラから D&D で自由にファイルを入れられる。ちゃんと入ったら、「Save」で「~/nuget」など適当なフォルダの中に入れる。

ちゃんとパッケージとして機能するかどうか、ローカルで試してみる。Visual Studio Express 2012 なら、「ツール」→「ライブラリ パッケージ マネージャ」→「ソリューションの NuGet パッケージの管理」を選んで、NuGet パッケージマネージャを起動する。

右下の「設定(S)」をクリックし、リポジトリ (利用可能なパッケージソース) に C:\Users\Ryohei\nuget など、さっき保存したフォルダへのパスを入力する。適当に名前をつける。

パッケージマネージャに戻って、「オンライン」から登録したローカルのパッケージソースを選択すると、さっき作ったパッケージがアップロードされていることが確認できる。インストールしてみて、フォルダ構成などを確認する。

あとは、再度NPEに戻り、「FILE」から「Publish」。 nuget.org で取得できる Deploy Key を入力すると、Publish できる。

参考: http://www.dotnetcurry.com/ShowArticle.aspx?ID=781