2016-08-15 126 views
2

我正在尋找從我的來源構建Nuget包的最簡單方法。我有Visual Studio 2015 Update 3,我的解決方案有一個.NET Core Class Library Project(基於project.json)。我正在嘗試從該項目創建一個包。目前爲了能夠這樣做,我創建了一個.nuspec文件並手動編輯它,即複製列在我的project.json文件中的所有依賴項。如何從project.json構建nuget包?

除了手動創建和編輯.nuspec文件之外,還有更好的方法嗎?如果我在project.json中進行了更改,我還必須在.nuspec文件中反映它們,這聽起來很奇怪。

順便說一句,這guide不適合我,因爲沒有 '生產上生成輸出' 複選框

雖然安裝了Microsoft ASP.NET和Web Tools

enter image description here

我錯過了什麼嗎?

回答

2

這些都是我們遵循我們的項目產生的NuGet步驟套餐的

1.Download Nuget.exe,並將其放置在那裏.csproj文件所在的文件夾中。

2.打開cmd並輸入nuget spec。帶有.nuspec擴展名的文件將被創建。

3.Open創建的文件,並添加標籤:

<files> <file src="..\..\SomeRoot\**\*.*" target="libs\net461" /> </files> 

4.Execute nuget pack A.csproj –IncludeReferencedProjects在cmd中。帶有.nupkg擴展名的文件被創建。

5.轉到視覺工作室。在NuGet程序包管理器設置中,添加「程序包源代碼」並提供您的文件存在.nupkg.nuspec的路徑。

6.關閉Nuget包管理器並再次打開它。現在,您可以在瀏覽選項卡下的創建包中找到它。

注意:您的.nuspec文件應該是這樣的:

<?xml version="1.0"?> 
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> 
    <id>ABC.XYZ.FL</id> 
    <version>1.0.0.0</version> 
    <title>ABC.XYZ.FL</title> 
    <authors>ABC</authors> 
    <owners>ABC</owners> 
    <requireLicenseAcceptance>false</requireLicenseAcceptance> 
    <description>Framework that will be used to create objects in XYZ world</description> 
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes> 
    <copyright>2016</copyright> 
    <tags>ABC.XYZ.FL</tags> 
    </metadata> 
    <files> 
    <file src="bin\Debug\*.dll" target="lib\net461" /> 
    </files> 
</package> 

以下鏈接包含有關創建NuGet包並在本地託管它的詳細信息:

https://docs.nuget.org/create/creating-and-publishing-a-package

https://docs.nuget.org/create/hosting-your-own-nuget-feeds

https://docs.nuget.org/consume/nuget-config-file

看看這是否有幫助。


編輯:

這裏是供您參考DOTNET包命令樣本 -

"scripts": { 
    "postcompile": [ 
    "dotnet pack --no-build --configuration %compile:Configuration%" 
    ] 
} 
+0

沒有。 csproj文件。相反,project.json用於列出所有依賴關係的地方。我的問題是,我正在尋找一種避免手動複製依賴關係的方法。 nuspec文件,當他們改變。 – neleus

+0

您是否嘗試過'dotnet pack'命令? – Sanket

+0

哦,我是對的,我錯過了這個!謝謝。你可以改正你的答案,然後我可以接受它。 – neleus

相關問題