nuget.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. CPack NuGet Generator
  2. ---------------------
  3. .. versionadded:: 3.12
  4. When build a NuGet package there is no direct way to control an output
  5. filename due a lack of the corresponding CLI option of NuGet, so there
  6. is no :variable:`!CPACK_NUGET_PACKAGE_FILE_NAME` variable. To form the output filename
  7. NuGet uses the package name and the version according to its built-in rules.
  8. Also, be aware that including a top level directory
  9. (:variable:`CPACK_INCLUDE_TOPLEVEL_DIRECTORY`) is ignored by this generator.
  10. Variables specific to CPack NuGet generator
  11. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12. The CPack NuGet generator may be used to create NuGet packages using
  13. :module:`CPack`. The CPack NuGet generator is a :module:`CPack` generator thus
  14. it uses the :variable:`!CPACK_XXX` variables used by :module:`CPack`.
  15. The CPack NuGet generator has specific features which are controlled by the
  16. specifics :variable:`!CPACK_NUGET_XXX` variables. In the "one per group" mode
  17. (see :variable:`CPACK_COMPONENTS_GROUPING`), ``<compName>`` placeholder
  18. in the variables below would contain a group name (uppercased and turned into
  19. a "C" identifier).
  20. List of CPack NuGet generator specific variables:
  21. .. variable:: CPACK_NUGET_COMPONENT_INSTALL
  22. Enable component packaging for CPack NuGet generator
  23. :Mandatory: No
  24. :Default: ``OFF``
  25. .. variable:: CPACK_NUGET_PACKAGE_DEBUG
  26. Enable debug messages while executing CPack NuGet generator.
  27. :Mandatory: No
  28. :Default: ``OFF``
  29. Required metadata variables
  30. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  31. .. variable:: CPACK_NUGET_PACKAGE_NAME
  32. CPACK_NUGET_<compName>_PACKAGE_NAME
  33. The NUGET package name. ``CPACK_NUGET_PACKAGE_NAME`` is used as the
  34. package ``id`` on nuget.org_
  35. :Mandatory: Yes
  36. :Default: :variable:`CPACK_PACKAGE_NAME`
  37. .. variable:: CPACK_NUGET_PACKAGE_VERSION
  38. CPACK_NUGET_<compName>_PACKAGE_VERSION
  39. The NuGet package version.
  40. :Mandatory: Yes
  41. :Default: :variable:`CPACK_PACKAGE_VERSION`
  42. .. variable:: CPACK_NUGET_PACKAGE_DESCRIPTION
  43. CPACK_NUGET_<compName>_PACKAGE_DESCRIPTION
  44. A long description of the package for UI display.
  45. :Mandatory: Yes
  46. :Default:
  47. - :variable:`CPACK_COMPONENT_<compName>_DESCRIPTION`,
  48. - :variable:`!CPACK_COMPONENT_GROUP_<groupName>_DESCRIPTION`,
  49. - :variable:`CPACK_PACKAGE_DESCRIPTION`
  50. .. variable:: CPACK_NUGET_PACKAGE_AUTHORS
  51. CPACK_NUGET_<compName>_PACKAGE_AUTHORS
  52. A comma-separated list of packages authors, matching the profile names
  53. on nuget.org_. These are displayed in the NuGet Gallery on
  54. nuget.org_ and are used to cross-reference packages by the same
  55. authors.
  56. :Mandatory: Yes
  57. :Default: :variable:`CPACK_PACKAGE_VENDOR`
  58. Optional metadata variables
  59. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  60. .. variable:: CPACK_NUGET_PACKAGE_OWNERS
  61. CPACK_NUGET_<compName>_PACKAGE_OWNERS
  62. .. deprecated:: 3.30
  63. Use authors (:variable:`CPACK_NUGET_PACKAGE_AUTHORS`) instead.
  64. A comma-separated list of the package creators using profile names
  65. on nuget.org_. This is often the same list as in authors,
  66. and is ignored when uploading the package to nuget.org_.
  67. :Mandatory: No
  68. :Default: None
  69. .. variable:: CPACK_NUGET_PACKAGE_HOMEPAGE_URL
  70. CPACK_NUGET_<compName>_PACKAGE_HOMEPAGE_URL
  71. An URL for the package's home page, often shown in UI displays as well
  72. as nuget.org_.
  73. :Mandatory: No
  74. :Default: :variable:`CPACK_PACKAGE_HOMEPAGE_URL`
  75. .. variable:: CPACK_NUGET_PACKAGE_LICENSEURL
  76. CPACK_NUGET_<compName>_PACKAGE_LICENSEURL
  77. .. deprecated:: 3.20
  78. Use a local license file
  79. (:variable:`CPACK_NUGET_PACKAGE_LICENSE_FILE_NAME`)
  80. or a `SPDX license identifier`_
  81. (:variable:`CPACK_NUGET_PACKAGE_LICENSE_EXPRESSION`) instead.
  82. An URL for the package's license, often shown in UI displays as well
  83. as on nuget.org_.
  84. :Mandatory: No
  85. :Default: None
  86. :Supported: NuGet 4.9.0 and above
  87. .. variable:: CPACK_NUGET_PACKAGE_LICENSE_FILE_NAME
  88. CPACK_NUGET_<compName>_PACKAGE_LICENSE_FILE_NAME
  89. .. versionadded:: 3.20
  90. The package's license file in :file:`.txt` or :file:`.md` format.
  91. If :variable:`!CPACK_NUGET_PACKAGE_LICENSE_FILE_NAME` is specified,
  92. :variable:`!CPACK_NUGET_PACKAGE_LICENSE_EXPRESSION` is ignored.
  93. :Mandatory: No
  94. :Default: None
  95. :Supported: NuGet 4.9.0 and above
  96. .. variable:: CPACK_NUGET_PACKAGE_LICENSE_EXPRESSION
  97. CPACK_NUGET_<compName>_PACKAGE_LICENSE_EXPRESSION
  98. .. versionadded:: 3.20
  99. A Software Package Data Exchange `SPDX license identifier`_ such as
  100. ``MIT``, ``BSD-3-Clause``, or ``LGPL-3.0-or-later``. In the case of a
  101. choice of licenses or more complex restrictions, compound license
  102. expressions may be formed using boolean operators, for example
  103. ``MIT OR BSD-3-Clause``. See the `SPDX specification`_ for guidance
  104. on forming complex license expressions.
  105. If :variable:`CPACK_NUGET_PACKAGE_LICENSE_FILE_NAME` is specified,
  106. :variable:`!CPACK_NUGET_PACKAGE_LICENSE_EXPRESSION` is ignored.
  107. :Mandatory: No
  108. :Default: None
  109. .. variable:: CPACK_NUGET_PACKAGE_ICONURL
  110. CPACK_NUGET_<compName>_PACKAGE_ICONURL
  111. .. deprecated:: 3.20
  112. Use a local icon file (:variable:`CPACK_NUGET_PACKAGE_ICON`) instead.
  113. An URL for a 64x64 image with transparency background to use as the
  114. icon for the package in UI display.
  115. :Mandatory: No
  116. :Default: None
  117. .. variable:: CPACK_NUGET_PACKAGE_ICON
  118. CPACK_NUGET_<compName>_PACKAGE_ICON
  119. .. versionadded:: 3.20
  120. The filename of a 64x64 image with transparency background to use as the
  121. icon for the package in UI display.
  122. :Mandatory: No
  123. :Default: None
  124. :Supported: NuGet 5.3.0 and above
  125. .. variable:: CPACK_NUGET_PACKAGE_README
  126. CPACK_NUGET_<compName>_PACKAGE_README
  127. .. versionadded:: 3.30
  128. The package path relative to the root of the package to a readme file.
  129. Supported file formats include only Markdown (``*.md``).
  130. :Mandatory: No
  131. :Default: None
  132. :Supported: NuGet 5.10.0 preview 2 and above
  133. .. variable:: CPACK_NUGET_PACKAGE_REQUIRE_LICENSE_ACCEPTANCE
  134. When set to a true value, the user will be prompted to accept the license
  135. before installing the package.
  136. :Mandatory: No
  137. :Default: None
  138. .. variable:: CPACK_NUGET_PACKAGE_DESCRIPTION_SUMMARY
  139. CPACK_NUGET_<compName>_PACKAGE_DESCRIPTION_SUMMARY
  140. .. deprecated:: 3.30
  141. Summary is being deprecated. Use description
  142. (:variable:`CPACK_NUGET_PACKAGE_DESCRIPTION`) instead.
  143. A short description of the package for UI display. If omitted, a
  144. truncated version of description is used.
  145. :Mandatory: No
  146. :Default: :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY`
  147. .. variable:: CPACK_NUGET_PACKAGE_RELEASE_NOTES
  148. CPACK_NUGET_<compName>_PACKAGE_RELEASE_NOTES
  149. A description of the changes made in this release of the package,
  150. often used in UI like the Updates tab of the Visual Studio Package
  151. Manager in place of the package description.
  152. :Mandatory: No
  153. :Default: None
  154. .. variable:: CPACK_NUGET_PACKAGE_COPYRIGHT
  155. CPACK_NUGET_<compName>_PACKAGE_COPYRIGHT
  156. Copyright details for the package.
  157. :Mandatory: No
  158. :Default: None
  159. .. variable:: CPACK_NUGET_PACKAGE_LANGUAGE
  160. CPACK_NUGET_<compName>_PACKAGE_LANGUAGE
  161. .. versionadded:: 3.20
  162. Locale specifier for the package, for example ``en_CA``.
  163. :Mandatory: No
  164. :Default: None
  165. .. variable:: CPACK_NUGET_PACKAGE_TAGS
  166. CPACK_NUGET_<compName>_PACKAGE_TAGS
  167. A space-delimited list of tags and keywords that describe the
  168. package and aid discoverability of packages through search and
  169. filtering.
  170. :Mandatory: No
  171. :Default: None
  172. .. variable:: CPACK_NUGET_PACKAGE_REPOSITORY_URL
  173. CPACK_NUGET_<compName>_REPOSITORY_URL
  174. .. versionadded:: 3.30
  175. Repository metadata allows you to map the ``*.nupkg`` to the repository
  176. that built it. This should be a publicly available URL that can be invoked
  177. directly by a version control software. It should not be an HTML page as
  178. this is meant for the computer.
  179. :Mandatory: No
  180. :Default: None
  181. :Supported: NuGet 4.0 and above
  182. .. variable:: CPACK_NUGET_PACKAGE_REPOSITORY_TYPE
  183. CPACK_NUGET_<compName>_REPOSITORY_TYPE
  184. .. versionadded:: 3.30
  185. A type of the VCS repository. When uploading a package to nuget.org_, the
  186. type is limited to 100 characters.
  187. :Mandatory: Yes, if repository URL has been specified
  188. :Default: None
  189. :Supported: NuGet 4.0 and above
  190. .. variable:: CPACK_NUGET_PACKAGE_REPOSITORY_BRANCH
  191. CPACK_NUGET_<compName>_REPOSITORY_BRANCH
  192. .. versionadded:: 3.30
  193. A VSC branch name to build the package.
  194. :Mandatory: No
  195. :Default: None
  196. :Supported: NuGet 4.6 and above
  197. .. variable:: CPACK_NUGET_PACKAGE_REPOSITORY_COMMIT
  198. CPACK_NUGET_<compName>_REPOSITORY_COMMIT
  199. .. versionadded:: 3.30
  200. A SHA-1 hash of the commit to build the package.
  201. :Mandatory: No
  202. :Default: None
  203. :Supported: NuGet 4.6 and above
  204. .. variable:: CPACK_NUGET_PACKAGE_TITLE
  205. CPACK_NUGET_<compName>_PACKAGE_TITLE
  206. A human-friendly title of the package, typically used in UI displays
  207. as on nuget.org_ and the Package Manager in Visual Studio. If not
  208. specified, the package ID is used.
  209. :Mandatory: No
  210. :Default:
  211. - :variable:`CPACK_COMPONENT_<compName>_DISPLAY_NAME`,
  212. - :variable:`!CPACK_COMPONENT_GROUP_<groupName>_DISPLAY_NAME`
  213. Dependencies specification
  214. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  215. .. variable:: CPACK_NUGET_PACKAGE_DEPENDENCIES
  216. CPACK_NUGET_<compName>_PACKAGE_DEPENDENCIES
  217. A list of default (not framework-specific) package dependencies.
  218. :Mandatory: No
  219. :Default: None
  220. .. variable:: CPACK_NUGET_PACKAGE_DEPENDENCIES_<dependency>_VERSION
  221. CPACK_NUGET_<compName>_PACKAGE_DEPENDENCIES_<dependency>_VERSION
  222. A `version specification`_ for the particular dependency, where
  223. ``<dependency>`` is an item of the dependency list (see above).
  224. :Mandatory: No
  225. :Default: None
  226. .. variable:: CPACK_NUGET_PACKAGE_TFMS
  227. CPACK_NUGET_<compName>_PACKAGE_TFMS
  228. .. versionadded:: 3.30
  229. A list of Target Framework Monikers (TFMs) for the package, e.g., "net47;netcoreapp21".
  230. For each of these TFMs a `dependency group`_ will be generated in the dependencies block of the NuGet
  231. package. Framework-specific dependencies can be added to these groups with the TFM
  232. dependency lists (see below).
  233. This variable is particularly useful for fixing warnings `NU5128`_.
  234. :Mandatory: No
  235. :Default: None
  236. .. variable:: CPACK_NUGET_PACKAGE_DEPENDENCIES_<tfm>
  237. CPACK_NUGET_<compName>_PACKAGE_DEPENDENCIES_<tfm>
  238. .. versionadded:: 3.30
  239. A list of package dependencies that apply specifically to the ``<tfm>`` framework, where ``<tfm>``
  240. is an item from the TFMs list (see above).
  241. :Mandatory: No
  242. :Default: None
  243. .. variable:: CPACK_NUGET_PACKAGE_DEPENDENCIES_<tfm>_<dependency>_VERSION
  244. CPACK_NUGET_<compName>_PACKAGE_DEPENDENCIES_<tfm>_<dependency>_VERSION
  245. .. versionadded:: 3.30
  246. A `version specification`_ for the particular framework-specific dependency, where
  247. ``<dependency>`` is an item of the ``<tfm>``-specific dependency list (see above).
  248. :Mandatory: No
  249. :Default: None
  250. Example usage
  251. ^^^^^^^^^^^^^
  252. .. code-block:: cmake
  253. set(CPACK_GENERATOR NuGet)
  254. # Set up package metadata
  255. set(CPACK_PACKAGE_NAME SamplePackage)
  256. set(CPACK_PACKAGE_VERSION "1.0.0")
  257. set(CPACK_PACKAGE_VENDOR "Example Inc")
  258. set(CPACK_NUGET_PACKAGE_AUTHORS "ExampleInc")
  259. set(CPACK_PACKAGE_DESCRIPTION "A .NET wrapper around the foobar library for frobbling bratchens")
  260. set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.example.com")
  261. set(CPACK_NUGET_PACKAGE_REPOSITORY_URL "https://github.com/example/libfoobar.git")
  262. set(CPACK_NUGET_PACKAGE_REPOSITORY_TYPE git)
  263. set(CPACK_NUGET_PACKAGE_LICENSE_EXPRESSION "MIT")
  264. # Set up dependencies
  265. set(CPACK_NUGET_PACKAGE_TFMS "net4;net6.0")
  266. set(CPACK_NUGET_PACKAGE_DEPENDENCIES_net4 "Foo;Bar")
  267. # NB: If a version number is omitted, the dependency will not be created
  268. set(CPACK_NUGET_PACKAGE_DEPENDENCIES_net4_Foo_VERSION "1.23")
  269. set(CPACK_NUGET_PACKAGE_DEPENDENCIES_net4_Bar_VERSION "4.3.2")
  270. # NB: General dependencies (not framework-specific) go in this variable
  271. set(CPACK_NUGET_PACKAGE_DEPENDENCIES "Baz")
  272. set(CPACK_NUGET_PACKAGE_DEPENDENCIES_Baz_VERSION "9.8.6")
  273. # NB: Since "net6.0" was listed but no dependencies have been specified, an empty group
  274. # will be added to the nuspec file for this framework. This can be used to address warning NU5128.
  275. include(CPack)
  276. .. _nuget.org: https://www.nuget.org
  277. .. _version specification: https://learn.microsoft.com/en-us/nuget/concepts/package-versioning#version-ranges
  278. .. _SPDX license identifier: https://spdx.org/licenses
  279. .. _SPDX specification: https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions
  280. .. _dependency group: https://learn.microsoft.com/en-us/nuget/reference/nuspec#dependency-groups
  281. .. _NU5128: https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5128
  282. .. NuGet spec docs https://docs.microsoft.com/en-us/nuget/reference/nuspec