2017-04-07 199 views
7

我想創建一個NuGet包,它將添加多個.dll文件作爲對我的項目的引用。從dll創建nuget包

我有一個包含10個.dlls文件的文件夾。

當我通過nuget安裝它時,我想將這些文件添加到項目的引用中。

+0

有沒有神奇的工具來自動化,你必須學習.nuspec和包裝的方式。 –

回答

18

我想創建一個nuget包,它添加了多個.dll作爲我的項目的引用。

我想給你們兩個解決方案,以實現這一目標:

首先,使用的NuGet Package Explorer中

  1. 下載NuGet Package Explorer
  2. 打開NuGet包資源管理器,選擇創建一個新包。
  3. 在內容標籤上添加一個lib文件夾,並添加你的dll文件
  4. 保存包並將其安裝到項目中,檢查它是否添加了引用。

NuGet Package Explorer GUI

其次,正如李萊克斯提,我們可以使用.nuspec收拾組件

  1. 下載nuget.exe
  2. 創建一個新項目。
  3. 打開以nuget.exe
  4. 使用命令行一個cmd和開關路徑:nuget spec "PathOfProject\TestDemo.csproj"
  5. 打開TestDemo.csproj.nuspec文件並對其進行修改和添加組件作爲文件;下面是我的.nuspec文件:

    <?xml version="1.0"?> <package > <metadata> <id>TestDemo</id> <version>1.0.0</version> <authors>Tester</authors> <owners>Tester</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>TestDemo</description> <releaseNotes>Summary of changes made in this release of the package. </releaseNotes> <copyright>Copyright 2017</copyright> <tags>Tag1 Tag2</tags> </metadata> <files> <file src="MultipleDll\*.*" target="lib\net461" /> </files> </package>

  6. 使用包命令:nuget pack TestDemo.csproj.nuspec

  7. 打開TestDemo包通過的NuGet軟件包瀏覽器。

NuGet Package Explorer - built package output

希望這可以幫助你。