コンパイルされたライブラリを NuGet パッケージに追加する

· 1分で読める

つい先日、アップロードした nuget パッケージからのものであるため、存在するはずのライブラリが欠落している NullReferenceException に関するバグを発見しました。

基本的に、いくつかのプロジェクトを参照するライブラリ クラスをコンパイルしました。ビルドフェーズでは、dll ファイルを bin フォルダーに追加しますが、それを nuget パッケージとして packaging して別のソリューションにインストールすると、参照し、bin フォルダーにコピーする必要がある dll ファイルがそこにありません。

解決方法

この問題の解決は非常に簡単です。 nuspec ファイルを更新し、コピーするライブラリごとに files 部分に file を追加する必要があります。

<?xml version="1.0" encoding="utf-8"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <license type="expression">MIT</license>
    <projectUrl>$projectUrl$</projectUrl>
    <iconUrl>$projectIconUrl$</iconUrl>
    <description>$description$</description>
    <releaseNotes></releaseNotes>
    <copyright>$copyright$</copyright>
    <tags></tags>
  </metadata>
  <files>
        <file src="bin\Release\MyFile1.dll" target="lib\net47" />
        <file src="bin\Release\MyFile2.dll" target="lib\net47" />
        <file src="bin\Release\MyFile3.dll" target="lib\net47" />
        <file src="bin\Release\MyFile4.dll" target="lib\net47" />
   </files>
</package>