nuget.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. .. variable:: CPACK_NUGET_PACKAGE_LICENSE_FILE_NAME
  87. CPACK_NUGET_<compName>_PACKAGE_LICENSE_FILE_NAME
  88. .. versionadded:: 3.20
  89. The package's license file in :file:`.txt` or :file:`.md` format.
  90. If :variable:`!CPACK_NUGET_PACKAGE_LICENSE_FILE_NAME` is specified,
  91. :variable:`!CPACK_NUGET_PACKAGE_LICENSE_EXPRESSION` is ignored.
  92. :Mandatory: No
  93. :Default: None
  94. .. variable:: CPACK_NUGET_PACKAGE_LICENSE_EXPRESSION
  95. CPACK_NUGET_<compName>_PACKAGE_LICENSE_EXPRESSION
  96. .. versionadded:: 3.20
  97. A Software Package Data Exchange `SPDX license identifier`_ such as
  98. ``MIT``, ``BSD-3-Clause``, or ``LGPL-3.0-or-later``. In the case of a
  99. choice of licenses or more complex restrictions, compound license
  100. expressions may be formed using boolean operators, for example
  101. ``MIT OR BSD-3-Clause``. See the `SPDX specification`_ for guidance
  102. on forming complex license expressions.
  103. If :variable:`CPACK_NUGET_PACKAGE_LICENSE_FILE_NAME` is specified,
  104. :variable:`!CPACK_NUGET_PACKAGE_LICENSE_EXPRESSION` is ignored.
  105. :Mandatory: No
  106. :Default: None
  107. .. variable:: CPACK_NUGET_PACKAGE_ICONURL
  108. CPACK_NUGET_<compName>_PACKAGE_ICONURL
  109. .. deprecated:: 3.20
  110. Use a local icon file (:variable:`CPACK_NUGET_PACKAGE_ICON`) instead.
  111. An URL for a 64x64 image with transparency background to use as the
  112. icon for the package in UI display.
  113. :Mandatory: No
  114. :Default: None
  115. .. variable:: CPACK_NUGET_PACKAGE_ICON
  116. CPACK_NUGET_<compName>_PACKAGE_ICON
  117. .. versionadded:: 3.20
  118. The filename of 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_REQUIRE_LICENSE_ACCEPTANCE
  123. When set to a true value, the user will be prompted to accept the license
  124. before installing the package.
  125. :Mandatory: No
  126. :Default: None
  127. .. variable:: CPACK_NUGET_PACKAGE_DESCRIPTION_SUMMARY
  128. CPACK_NUGET_<compName>_PACKAGE_DESCRIPTION_SUMMARY
  129. .. deprecated:: 3.30
  130. Summary is being deprecated. Use description
  131. (:variable:`CPACK_NUGET_PACKAGE_DESCRIPTION`) instead.
  132. A short description of the package for UI display. If omitted, a
  133. truncated version of description is used.
  134. :Mandatory: No
  135. :Default: :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY`
  136. .. variable:: CPACK_NUGET_PACKAGE_RELEASE_NOTES
  137. CPACK_NUGET_<compName>_PACKAGE_RELEASE_NOTES
  138. A description of the changes made in this release of the package,
  139. often used in UI like the Updates tab of the Visual Studio Package
  140. Manager in place of the package description.
  141. :Mandatory: No
  142. :Default: None
  143. .. variable:: CPACK_NUGET_PACKAGE_COPYRIGHT
  144. CPACK_NUGET_<compName>_PACKAGE_COPYRIGHT
  145. Copyright details for the package.
  146. :Mandatory: No
  147. :Default: None
  148. .. variable:: CPACK_NUGET_PACKAGE_LANGUAGE
  149. CPACK_NUGET_<compName>_PACKAGE_LANGUAGE
  150. .. versionadded:: 3.20
  151. Locale specifier for the package, for example ``en_CA``.
  152. :Mandatory: No
  153. :Default: None
  154. .. variable:: CPACK_NUGET_PACKAGE_TAGS
  155. CPACK_NUGET_<compName>_PACKAGE_TAGS
  156. A space-delimited list of tags and keywords that describe the
  157. package and aid discoverability of packages through search and
  158. filtering.
  159. :Mandatory: No
  160. :Default: None
  161. .. variable:: CPACK_NUGET_PACKAGE_TITLE
  162. CPACK_NUGET_<compName>_PACKAGE_TITLE
  163. A human-friendly title of the package, typically used in UI displays
  164. as on nuget.org_ and the Package Manager in Visual Studio. If not
  165. specified, the package ID is used.
  166. :Mandatory: No
  167. :Default:
  168. - :variable:`CPACK_COMPONENT_<compName>_DISPLAY_NAME`,
  169. - :variable:`!CPACK_COMPONENT_GROUP_<groupName>_DISPLAY_NAME`
  170. Dependencies specification
  171. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  172. .. variable:: CPACK_NUGET_PACKAGE_DEPENDENCIES
  173. CPACK_NUGET_<compName>_PACKAGE_DEPENDENCIES
  174. A list of default (not framework-specific) package dependencies.
  175. :Mandatory: No
  176. :Default: None
  177. .. variable:: CPACK_NUGET_PACKAGE_DEPENDENCIES_<dependency>_VERSION
  178. CPACK_NUGET_<compName>_PACKAGE_DEPENDENCIES_<dependency>_VERSION
  179. A `version specification`_ for the particular dependency, where
  180. ``<dependency>`` is an item of the dependency list (see above).
  181. :Mandatory: No
  182. :Default: None
  183. .. variable:: CPACK_NUGET_PACKAGE_TFMS
  184. CPACK_NUGET_<compName>_PACKAGE_TFMS
  185. .. versionadded:: 3.30
  186. A list of Target Framework Monikers (TFMs) for the package, e.g., "net47;netcoreapp21".
  187. For each of these TFMs a `dependency group`_ will be generated in the dependencies block of the NuGet
  188. package. Framework-specific dependencies can be added to these groups with the TFM
  189. dependency lists (see below).
  190. This variable is particularly useful for fixing warnings `NU5128`_.
  191. :Mandatory: No
  192. :Default: None
  193. .. variable:: CPACK_NUGET_PACKAGE_DEPENDENCIES_<tfm>
  194. CPACK_NUGET_<compName>_PACKAGE_DEPENDENCIES_<tfm>
  195. .. versionadded:: 3.30
  196. A list of package dependencies that apply specifically to the ``<tfm>`` framework, where ``<tfm>``
  197. is an item from the TFMs list (see above).
  198. :Mandatory: No
  199. :Default: None
  200. .. variable:: CPACK_NUGET_PACKAGE_DEPENDENCIES_<tfm>_<dependency>_VERSION
  201. CPACK_NUGET_<compName>_PACKAGE_DEPENDENCIES_<tfm>_<dependency>_VERSION
  202. .. versionadded:: 3.30
  203. A `version specification`_ for the particular framework-specific dependency, where
  204. ``<dependency>`` is an item of the ``<tfm>``-specific dependency list (see above).
  205. :Mandatory: No
  206. :Default: None
  207. Example usage
  208. ^^^^^^^^^^^^^
  209. .. code-block:: cmake
  210. set(CPACK_GENERATOR NuGet)
  211. # Set up package metadata
  212. set(CPACK_PACKAGE_NAME SamplePackage)
  213. set(CPACK_PACKAGE_VERSION "1.0.0")
  214. set(CPACK_PACKAGE_VENDOR "Example Inc")
  215. set(CPACK_NUGET_PACKAGE_OWNERS "Example Inc")
  216. set(CPACK_PACKAGE_DESCRIPTION "A .NET wrapper around the foobar library for frobbling bratchens")
  217. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A .NET wrapper around the foobar library for frobbling bratchens")
  218. set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.example.com")
  219. set(CPACK_NUGET_PACKAGE_REPOSITORY_URL "https://github.com/example/libfoobar.git")
  220. set(CPACK_NUGET_PACKAGE_REPOSITORY_TYPE git)
  221. set(CPACK_NUGET_PACKAGE_LICENSE_EXPRESSION "MIT")
  222. # Set up dependencies
  223. set(CPACK_NUGET_PACKAGE_TFMS "net4;net6.0")
  224. set(CPACK_NUGET_PACKAGE_DEPENDENCIES_net4 "Foo;Bar")
  225. # NB: If a version number is omitted, the dependency will not be created
  226. set(CPACK_NUGET_PACKAGE_DEPENDENCIES_net4_Foo_VERSION "1.23")
  227. set(CPACK_NUGET_PACKAGE_DEPENDENCIES_net4_Bar_VERSION "4.3.2")
  228. # NB: General dependencies (not framework-specific) go in this variable
  229. set(CPACK_NUGET_PACKAGE_DEPENDENCIES "Baz")
  230. set(CPACK_NUGET_PACKAGE_DEPENDENCIES_Baz_VERSION "9.8.6")
  231. # NB: Since "net6.0" was listed but no dependencies have been specified, an empty group
  232. # will be added to the nuspec file for this framework. This can be used to address warning NU5128.
  233. include(CPack)
  234. .. _nuget.org: https://www.nuget.org
  235. .. _version specification: https://learn.microsoft.com/en-us/nuget/concepts/package-versioning#version-ranges
  236. .. _SPDX license identifier: https://spdx.org/licenses
  237. .. _SPDX specification: https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions
  238. .. _dependency group: https://learn.microsoft.com/en-us/nuget/reference/nuspec#dependency-groups
  239. .. _NU5128: https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5128
  240. .. NuGet spec docs https://docs.microsoft.com/en-us/nuget/reference/nuspec