-
Notifications
You must be signed in to change notification settings - Fork 0
/
building-nupkg.htm
196 lines (177 loc) · 7.71 KB
/
building-nupkg.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
<title>How to build and install nuget packages (.nupkg) from sources ?</title>
<style>
span.tab1 { margin-left:32px;}
span.tab2 { margin-left:64px;}
</style>
<!--
span.tab3 { margin-left:192px;}
span.tab4 { margin-left:256px;}
span.tab5 { margin-left:288px;}
span.tab6 { margin-left:320px;}
-->
</head>
<body><a href="https://github.com/ArsenShnurkov/gentoo-mono-handbook"><img alt="Fork me on GitHub" id="forkme" src="images/forkme.png" align="right" width="100" /></a>
<table><tr><td valign="top">
<h1>How to build and install nuget packages (.nupkg) from sources ?</h1>
</td><td valign="top">
<a href="index.htm">Gentoo Mono Handbook</a>
<br />
</td></tr></table>
.nuspec manifest is used to build a package and is also stored in the package after the package is built.
<br />
<br />
<a href="https://developer.xamarin.com/guides/cross-platform/application_fundamentals/nuget_walkthrough/">How to include a NuGet package in a MonoDevelop Project</a>
<br />
<a href="https://developer.xamarin.com/guides/cross-platform/application_fundamentals/nuget_walkthrough/">https://developer.xamarin.com/guides/cross-platform/application_fundamentals/nuget_walkthrough/</a>
<h2>Typical .nuspec file</h2>
<pre>
<?xml version="1.0"?>
<package >
<metadata>
<id>$package_id$</id>
<version>$package_version$</version>
<authors>$package_authors$</authors>
<owners>$package_owners$</owners>
<licenseUrl>$package_licenseUrl$</licenseUrl>
<projectUrl>$package_ProjectUrl$</projectUrl>
<iconUrl>$package_iconUrl$</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$package_description$</description>
<releaseNotes>$package_releaseNotes$</releaseNotes>
<copyright>$package_copyright$</copyright>
<tags>$package_tags$</tags>
<!--
<dependencies>
<dependency id="SampleDependency" version="1.0" />
</dependencies>
-->
</metadata>
<!-- the package element can include a files element that specifies files to be included in the package.
If the files element is omitted, all files and folders that are
in the same folder as the .nuspec file are included in the package.
(q) https://docs.nuget.org/create/nuspec-reference-->
</package>
</pre>
<h3>replacement tokens and properties</h3>
<a href="https://docs.nuget.org/ndocs/schema/nuspec">https://docs.nuget.org/ndocs/schema/nuspec</a>
<dl>
<dt>-Properties</dt>
<dd>Provides the ability to specify a semicolon ";" delimited list of properties when creating a package.</dd>
</dl>
If one set Properties twice, then nuget will give the error:
<pre>
Invalid option value: '-Properties package_version=4.1.3'
</pre>
And this is not very good, because it become more difficult to provide default values for that properties
<br />
<br />
When you build the package by using MSBuild,
the properties defined for the build propagate through to the package build as values for replacement tokens.
They will have the same names as the properties in MSBuild,
which makes it possible to select files to be included
depending on the current build configuration. For instance:
<pre><files>
<file src="bin\$configuration$\$id$.pdb" target="lib\net40\" />
</files></pre>
<h3>How to set version</h3>
Replace specified version
<pre>
<version>1.0.0</version>
</pre>
with replacement token:
<pre>
<version>$version$</version>
</pre>
specify the property through nuget command line arguments in the ebuild:
<pre>
enuspec -Prop version=4.1.3 ./src/NuGet/NLog/NLog.nuspec
</pre>
<h2>Pack command</h2>
<a href="https://docs.nuget.org/Consume/Command-Line-Reference#pack-command">https://docs.nuget.org/Consume/Command-Line-Reference#pack-command</a>
<br />
The .nuspec file is included in the package after the package is built (but without the element that lists files if that element was included).
<br />
<br />
So, we need to copy file from ${FILESDIR} into output dir, and thus we will be able to use defaults.
<br />
<br />
or just add locations with a patch
<h2>How to create .nuspec file</h2>
In the folder where the csproj file is, run:
<br />
nuget spec
<br />
<pre><code>
# nuget spec SharpHsql.csproj
Created 'SharpHsql.csproj.nuspec' successfully.
</code></pre>
The file will have following content:
<pre>
<?xml version="1.0"?>
<package >
<metadata>
<id>NLog.mono4.csproj</id>
<version>1.0.0</version>
<authors>user</authors>
<owners>user</owners>
<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2015</copyright>
<tags>Tag1 Tag2</tags>
<dependencies>
<dependency id="SampleDependency" version="1.0" />
</dependencies>
</metadata>
</package>
</pre>
<h2>Default paths</h2>
you generate a blank nuspec file with:
<br />
nuget spec
<br />
If you use that file and then put your dlls in a folder under it named lib, it will package them up.
<br />
If you manually reference any files in the nuspec file, the conventions are not used.
<br />
you can tell nuget the location of your .\lib folder via the -BasePath command line:
<br />
build\nuget.exe pack nuget\Company.Project.nuspec -BasePath nuget\
<br />
<br />
You'll run NuGet on a single project (or nuspec file), but it supports pointers to other projects via the file element.
<br />
This element uses the names of your project's References, so you avoid having to
<br />
a) find the location of other project files, and
<br />
b) copy files to a particular place as a post-build step.
<br />
Supposing you have a nuspec file for MyLibrary.Core.csproj, and it references MyLibrary.Extensions and MyLibrary.Tests such that they end up in the bin directory after a build:
<br />
<br /><font type="tt"><package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"><br />
<span class="tab1"><metadata></span><br />
<span class="tab2">...</span><br />
<span class="tab1"></metadata></span><br />
<span class="tab1"><files></span><br />
<span class="tab2"><file src="bin\Release\MyLibrary.Extensions.dll" target="lib\net40" /></span><br />
<span class="tab2"><file src="bin\Release\MyLibrary.Tests.dll" target="lib\net40" /></span><br />
<span class="tab1"></files></span><br />
</package></font><br />
<br />
With this setup, all of your references should end up in the appropriate place in the NuGet package.
<br />
You still have the hard-coded 'Release' in there, but I'd wager
most probably don't distribute NuGet packages of their debug builds anyway.
<h2>Debug and Release configurations</h2>
<a href="https://github.com/mrward/monodevelop-nuget-addin/issues/62">https://github.com/mrward/monodevelop-nuget-addin/issues/62</a>
</body>
</html>