nuget.rst 13 KB

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