「マイクロソフト系技術情報 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。 目次 †概要 †
Nugetでできること。 †追加できるファイル †
パッケージの色々 †
その他 †
.NET Frameworkプロジェクト以外 †.NET Standard、.NET Core †
Native Package(C++) †C++の、Native Packageも作成できる模様。
基本的な手順 †
Nugetのサイトにサインイン †
NugetのサイトからNuget.exeを取得 †
nuspecファイルの生成 †nuspecファイルとは? †
nuspecファイルの出力準備 †
nuget.exeからnuspecファイルを出力 †
nuspecファイルの編集 †
以下、ザックリとした説明。 id †例 : Oracle.DataAccess?(.dll)とか、Microsoft.AspNet?.Identity(.dll)とか。
title †
description †パッケージのザックリとした説明。 authors、owners †
projectUrl、licenseUrl、iconUrl †各種URLを設定する。
version †
.NET Framework アセンブリへの参照の追加 †<frameworkAssemblies> <frameworkAssembly assemblyName="System.Web" /> </frameworkAssemblies> 他のNugetパッケージへの依存関係の追加 †<dependencies> <dependency id="jQuery" /> </dependencies> バージョンを指定可能。範囲指定も可能。
アセンブリの追加(*.dll) †targetを設定して、アセンブリ(*.dll)を同梱する。 <files> <file src="bin\Release\*.*" target="lib\net45" /> </files> 参考 †https://docs.microsoft.com/ja-jp/nuget/create-packages/creating-a-package <?xml version="1.0"?> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <metadata> <!-- The identifier that must be unique within the hosting gallery --> <!-- ホスティングギャラリー内で一意でなければならないID --> <id>Contoso.Utility.UsefulStuff</id> <!-- The package version number that is used when resolving dependencies --> <!-- 依存関係を解決するときに使用されるパッケージのバージョン番号 --> <version>1.8.3.331</version> <!-- Authors contain text that appears directly on the gallery --> <!-- Authorsには、ギャラリーに直接表示されるテキストが含まれています --> <authors>Dejana Tesic, Rajeev Dey</authors> <!-- Owners are typically nuget.org identities that allow gallery users to easily find other packages by the same owners. --> <!-- ownersは通常、ギャラリーのユーザーが同じownerによる他のパッケージを簡単に見つけることを可能にするnuget.org IDです。 --> <owners>dejanatc, rjdey</owners> <!-- License and project URLs provide links for the gallery --> <!-- licenseUrlとprojectUrlはギャラリーにリンクを提供します --> <licenseUrl>http://opensource.org/licenses/MS-PL</licenseUrl> <projectUrl>http://github.com/contoso/UsefulStuff</projectUrl> <!-- The icon is used in Visual Studio's package manager UI --> <!-- このアイコンは、Visual Studioのパッケージ・マネージャUIで使用されます --> <iconUrl>http://github.com/contoso/UsefulStuff/nuget_icon.png</iconUrl> <!-- If true, this value prompts the user to accept the license when installing the package. --> <!-- trueの場合、この値は、パッケージのインストール時にライセンスを受け入れるようにユーザーに指示します。 --> <requireLicenseAcceptance>false</requireLicenseAcceptance> <!-- Any details about this particular release --> <!-- このリリースに関する詳細 --> <releaseNotes>Bug fixes and performance improvements</releaseNotes> <!-- The description can be used in package manager UI. Note that the nuget.org gallery uses information you add in the portal. --> <!-- descriptionは、パッケージ・マネージャのUIで使用できます。 nuget.orgギャラリーでは、ポータルに追加した情報が使用されます。 --> <description>Core utility functions for web applications</description> <!-- Copyright information --> <!-- 著作権情報 --> <copyright>Copyright ©2016 Contoso Corporation</copyright> <!-- Tags appear in the gallery and can be used for tag searches --> <!-- tagsはギャラリーに表示され、tag検索に使用できます --> <tags>web utility http json url parsing</tags> <!-- Dependencies are automatically installed when the package is installed --> <!-- dependencyは、パッケージのインストール時に自動的に(他のパッケージが)インストールされます。 --> <dependencies> <dependency id="Newtonsoft.Json" version="9.0" /> </dependencies> </metadata> <!-- A readme.txt will be displayed when the package is installed --> <!-- パッケージのインストール時に readme.txt が表示されます --> <files> <file src="readme.txt" target="" /> </files> </package> パッケージ(nupkgファイル)の作成 †プロジェクト・ファイルを使用 †
nuspecファイルを使用 †
nupkgファイルの内容確認方法 †
NuGet への登録 †コマンドラインから †
Webサイトから †NuGet Gallery でアップロードする場合、API Keysは不要。
公開前に(ローカルで)テスト実行する。 †
バージョンアップする。 †nuspec ファイルの version を書き換えて同じように nupkg をアップロード。 高度な設定 †パッケージにファイルを含める †パッケージに含めるファイル †
作業ディレクトリのフォルダ構造レイアウトの規則 †
パッケージへのインクルード †nuspecファイルの<metadata>要素と同じ階層に、
複数のTarget Frameworksのサポート †https://docs.microsoft.com/ja-jp/nuget/create-packages/supporting-multiple-target-frameworks 「パッケージにファイルを含める」の方法で、複数バージョンを同梱するだけでいい。 設定 †以下は、nuspecファイルの設定例 <files> <file src="bin\Release\net46\MyAssembly.dll" target="lib\net46" /> <file src="bin\Release\net461\MyAssembly.dll" target="lib\net461" /> <file src="bin\Release\uap\MyAssembly.dll" target="lib\uap" /> <file src="bin\Release\netcore\MyAssembly.dll" target="lib\netcore" /> </files> 結果 †パッケージのインストール後のpackagesフォルダのlibフォルダは以下のようになる。
参考 †Dapperのnuspecファイルが参考になる。
.NET Standard、.NET CoreのDependencies †dependencies > group > targetFramework="netstandard2.0" 等とする。 <dependencies> <group> <dependency id="DotNetZip" version="1.12.0" /> <dependency id="log4net" version="2.0.8" /> <dependency id="Newtonsoft.Json" version="11.0.2" /> </group> <group targetFramework="netstandard2.0"> <dependency id="log4net" version="2.0.8" /> <dependency id="Microsoft.Extensions.Configuration" version="2.2.0" /> <dependency id="Microsoft.Extensions.Configuration.Binder" version="2.2.0" /> <dependency id="Microsoft.Extensions.Configuration.FileExtensions" version="2.2.0" /> <dependency id="Microsoft.Extensions.Configuration.Json" version="2.2.0" /> <dependency id="Newtonsoft.Json" version="11.0.2" /> <dependency id="System.Data.Odbc" version="4.5.0" /> <dependency id="System.Data.SqlClient" version="4.5.1" /> </group> </dependencies> 様々なパッケージ †Localized Package(ローカライズ) †https://docs.microsoft.com/ja-jp/nuget/create-packages/creating-localized-packages 以下の2つの方法がある。
Symbol Package(デバッグ用) †NuGetパッケージのプレリリース版 †package type †NuGet 3.5以降で設定可能。
注意 †一度登録すると通常消せない。 †
依存関係 †Dependenciesタグ †NuGetサイトに表示されるのは、*.nspecファイルのDependenciesタグ明記したもの。 自動的に追加されるNuGetパッケージ †しかし、NuGetから追加された時には、
不明だが自動的に依存関係にあるNuGetパッケージが追加される。 Symbolの作成・登録と公開方法の変更 †参考 †
Microsoft Docs †
nuspecファイルの定義例 †著名なパッケージを参考にする。 †
Open棟梁のパッケージを参考にする。 †
nuspecファイルのメタデータ要素 †
必要なメタデータ要素(最小要件) †
オプションのメタデータ要素(必要に応じて追加) †
NuGetパッケージ関連 †NuGetプライベート・リポジトリ †NuGetパッケージのデバッグ †NuGetパッケージのプレリリース版 †Open 棟梁 Wiki †NuGet導入、NuGet登録 †Open棟梁のバージョン番号付与ポリシー †OssCons?...TestClassLibrary1 †OSSコンソーシアム 開発基盤部で登録したテスト用ライブラリ
|