Skip to content

Commit 958e482

Browse files
authored
Merge pull request NuGet#1522 from NuGet/mikejo-updates
Refactored create topic
2 parents f1a95c3 + 35cb56e commit 958e482

File tree

8 files changed

+85
-64
lines changed

8 files changed

+85
-64
lines changed

docs/TOC.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@
3838
## [Create a symbol package](create-packages/symbol-packages-snupkg.md)
3939
## Advanced tasks
4040
### [Modify source code and config files](create-packages/source-and-config-file-transformations.md)
41-
### [Create a localized package](create-packages/creating-localized-packages.md)
4241
### [Select assemblies referenced by projects](create-packages/select-assemblies-referenced-by-projects.md)
42+
### [Set package type](create-packages/set-package-type.md)
43+
### [Create a localized package](create-packages/creating-localized-packages.md)
4344
## Guides for specific content
4445
### [Create a UWP package](guides/create-uwp-packages.md)
4546
### [Create a native package](create-packages/native-packages.md)
4647
### [Create UI controls as a NuGet package](guides/create-UI-controls.md)
4748
### [Create an analyzer as a NuGet package](reference/analyzers-conventions.md)
4849
### [Create a package for Xamarin with Visual Studio 2015](guides/create-packages-for-xamarin.md)
50+
### [Create a package with COM interop assemblies](create-packages/author-packages-with-COM-interop-assemblies.md)
4951
## Sign packages
5052
### [Sign a package](create-packages/sign-a-package.md)
5153
### [Signed package signatures and requirements](reference/signed-packages-reference.md)

docs/create-packages/Creating-a-Package.md

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.date: 05/24/2019
77
ms.topic: conceptual
88
---
99

10-
# Creating NuGet packages
10+
# Create NuGet packages
1111

1212
No matter what your package does or what code it contains, you use one of the CLI tools, either `nuget.exe` or `dotnet.exe`, to package that functionality into a component that can be shared with and used by any number of other developers. To install NuGet CLI tools, see [Install NuGet client tools](../install-nuget-client-tools.md). Note that Visual Studio does not automatically include a CLI tool.
1313

@@ -24,7 +24,7 @@ Packaging begins with the compiled code (assemblies), symbols, and/or other file
2424
> [!Note]
2525
> This topic applies to non-SDK-style projects, typically projects other than .NET Core and .NET Standard projects using Visual Studio 2017 and higher versions and NuGet 4.0+.
2626
27-
## Deciding which assemblies to package
27+
## Decide which assemblies to package
2828

2929
Most general-purpose packages contain one or more assemblies that other developers can use in their own projects.
3030

@@ -36,7 +36,7 @@ Most general-purpose packages contain one or more assemblies that other develope
3636

3737
Resources are, in fact, a special case. When a package is installed into a project, NuGet automatically adds assembly references to the package's DLLs, *excluding* those that are named `.resources.dll` because they are assumed to be localized satellite assemblies (see [Creating localized packages](creating-localized-packages.md)). For this reason, avoid using `.resources.dll` for files that otherwise contain essential package code.
3838

39-
If your library contains COM interop assemblies, follow additional the guidelines in [Authoring packages with COM interop assemblies](#authoring-packages-with-com-interop-assemblies).
39+
If your library contains COM interop assemblies, follow additional the guidelines in [Create packages with COM interop assemblies](author-packages-with-com-interop-assemblies.md).
4040

4141
## The role and structure of the .nuspec file
4242

@@ -146,7 +146,7 @@ Go into any *package\version* folder, copy the `.nupkg` file to a `.zip` file, t
146146
> [!Note]
147147
> When creating a `.nuspec` from a Visual Studio project, the manifest contains tokens that are replaced with information from the project when the package is built. See [Creating the .nuspec from a Visual Studio project](#from-a-visual-studio-project).
148148
149-
## Creating the .nuspec file
149+
## Create the .nuspec file
150150

151151
Creating a complete manifest typically begins with a basic `.nuspec` file generated through one of the following methods:
152152

@@ -223,7 +223,7 @@ This token is replaced with the `AssemblyName` value from the project file at pa
223223

224224
Tokens relieve you from needing to update crucial values like the version number in the `.nuspec` as you update the project. (You can always replace the tokens with literal values, if desired).
225225

226-
Note that there are several additional packaging options available when working from a Visual Studio project, as described in [Running nuget pack to generate the .nupkg file](#running-nuget-pack-to-generate-the-nupkg-file) later on.
226+
Note that there are several additional packaging options available when working from a Visual Studio project, as described in [Running nuget pack to generate the .nupkg file](#run-nuget-pack-to-generate-the-nupkg-file) later on.
227227

228228
#### Solution-level packages
229229

@@ -245,7 +245,7 @@ If you omit \<package-name\>, the resulting file is `Package.nuspec`. If you pro
245245

246246
The resulting `.nuspec` contains placeholders for values like the `projectUrl`. Be sure to edit the file before using it to create the final `.nupkg` file.
247247

248-
## Choosing a unique package identifier and setting the version number
248+
## Choose a unique package identifier and setting the version number
249249

250250
The package identifier (`<id>` element) and the version number (`<version>` element) are the two most important values in the manifest because they uniquely identify the exact code that's contained in the package.
251251

@@ -257,7 +257,7 @@ The package identifier (`<id>` element) and the version number (`<version>` elem
257257

258258
**Best practices for the package version:**
259259

260-
- In general, set the version of the package to match the library, though this is not strictly required. This is a simple matter when you limit a package to a single assembly, as described earlier in [Deciding which assemblies to package](#deciding-which-assemblies-to-package). Overall, remember that NuGet itself deals with package versions when resolving dependencies, not assembly versions.
260+
- In general, set the version of the package to match the library, though this is not strictly required. This is a simple matter when you limit a package to a single assembly, as described earlier in [Deciding which assemblies to package](#decide-which-assemblies-to-package). Overall, remember that NuGet itself deals with package versions when resolving dependencies, not assembly versions.
261261
- When using a non-standard version scheme, be sure to consider the NuGet versioning rules as explained in [Package versioning](../reference/package-versioning.md).
262262

263263
> The following series of brief blog posts are also helpful to understand versioning:
@@ -266,33 +266,7 @@ The package identifier (`<id>` element) and the version number (`<version>` elem
266266
> - [Part 2: The core algorithm](http://blog.davidebbo.com/2011/01/nuget-versioning-part-2-core-algorithm.html)
267267
> - [Part 3: Unification via Binding Redirects](http://blog.davidebbo.com/2011/01/nuget-versioning-part-3-unification-via.html)
268268
269-
## Setting a package type
270-
271-
With NuGet 3.5+, packages can be marked with a specific *package type* to indicate its intended use. Packages not marked with a type, including all packages created with earlier versions of NuGet, default to the `Dependency` type.
272-
273-
- `Dependency` type packages add build- or run-time assets to libraries and applications, and can be installed in any project type (assuming they are compatible).
274-
275-
- `DotnetCliTool` type packages are extensions to the [.NET CLI](/dotnet/articles/core/tools/index) and are invoked from the command line. Such packages can be installed only in .NET Core projects and have no effect on restore operations. More details about these per-project extensions are available in the [.NET Core extensibility](/dotnet/articles/core/tools/extensibility#per-project-based-extensibility) documentation.
276-
277-
- Custom type packages use an arbitrary type identifier that conforms to the same format rules as package IDs. Any type other than `Dependency` and `DotnetCliTool`, however, are not recognized by the NuGet Package Manager in Visual Studio.
278-
279-
Package types are set in the `.nuspec` file. It's best for backwards compatibility to *not* explicitly set the `Dependency` type and to instead rely on NuGet assuming this type when no type is specified.
280-
281-
- `.nuspec`: Indicate the package type within a `packageTypes\packageType` node under the `<metadata>` element:
282-
283-
```xml
284-
<?xml version="1.0" encoding="utf-8"?>
285-
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
286-
<metadata>
287-
<!-- ... -->
288-
<packageTypes>
289-
<packageType name="DotnetCliTool" />
290-
</packageTypes>
291-
</metadata>
292-
</package>
293-
```
294-
295-
## Adding a readme and other files
269+
## Add a readme and other files
296270

297271
To directly specify files to include in the package, use the `<files>` node in the `.nuspec` file, which *follows* the `<metadata>` tag:
298272

@@ -322,7 +296,7 @@ When you include a file named `readme.txt` in the package root, Visual Studio di
322296
> [!Note]
323297
> If you include an empty `<files>` node in the `.nuspec` file, NuGet doesn't include any other content in the package other than what's in the `lib` folder.
324298
325-
## Including MSBuild props and targets in a package
299+
## Include MSBuild props and targets in a package
326300

327301
In some cases, you might want to add custom build targets or properties in projects that consume your package, such as running a custom tool or process during build. You do this by placing files in the form `<package_id>.targets` or `<package_id>.props` (such as `Contoso.Utility.UsefulStuff.targets`) within the `\build` folder of the project.
328302

@@ -362,27 +336,7 @@ MSBuild `.props` and `.targets` files for cross-framework targeting can be place
362336

363337
With NuGet 3.x, targets are not added to the project but are instead made available through the `project.lock.json`.
364338

365-
## Authoring packages with COM interop assemblies
366-
367-
Packages that contain COM interop assemblies must include an appropriate [targets file](#including-msbuild-props-and-targets-in-a-package) so that the correct `EmbedInteropTypes` metadata is added to projects using the PackageReference format. By default, the `EmbedInteropTypes` metadata is always false for all assemblies when PackageReference is used, so the targets file adds this metadata explicitly. To avoid conflicts, the target name should be unique; ideally, use a combination of your package name and the assembly being embedded, replacing the `{InteropAssemblyName}` in the example below with that value. (Also see [NuGet.Samples.Interop](https://github.com/NuGet/Samples/tree/master/NuGet.Samples.Interop) for an example.)
368-
369-
```xml
370-
<Target Name="Embedding**AssemblyName**From**PackageId**" AfterTargets="ResolveReferences" BeforeTargets="FindReferenceAssembliesForReferences">
371-
<ItemGroup>
372-
<ReferencePath Condition=" '%(FileName)' == '{InteropAssemblyName}' AND '%(ReferencePath.NuGetPackageId)' == '$(MSBuildThisFileName)' ">
373-
<EmbedInteropTypes>true</EmbedInteropTypes>
374-
</ReferencePath>
375-
</ItemGroup>
376-
</Target>
377-
```
378-
379-
Note that when using the `packages.config` management format, adding references to the assemblies from the packages causes NuGet and Visual Studio to check for COM interop assemblies and set the `EmbedInteropTypes` to true in the project file. In this case the targets are overriden.
380-
381-
Additionally, by default the [build assets do not flow transitively](../consume-packages/package-references-in-project-files.md#controlling-dependency-assets). Packages authored as described here work differently when they are pulled as a transitive dependency from a project to project reference. The package consumer can allow them to flow by modifying the PrivateAssets default value to not include build.
382-
383-
<a name="creating-the-package"></a>
384-
385-
## Running nuget pack to generate the .nupkg file
339+
## Run nuget pack to generate the .nupkg file
386340

387341
When using an assembly or the convention-based working directory, create a package by running `nuget pack` with your `.nuspec` file, replacing `<project-name>` with your specific filename:
388342

@@ -436,7 +390,7 @@ The following options are a few that are common with Visual Studio projects:
436390
nuget pack MyProject.csproj -symbols
437391
```
438392
439-
### Testing package installation
393+
### Test package installation
440394
441395
Before publishing a package, you typically want to test the process of installing a package into a project. The tests make sure that the necessarily files all end up in their correct places in the project.
442396
@@ -460,6 +414,8 @@ You might also want to extend the capabilities of your package or otherwise supp
460414
- [Transformations of source and configuration files](../create-packages/source-and-config-file-transformations.md)
461415
- [Localization](../create-packages/creating-localized-packages.md)
462416
- [Pre-release versions](../create-packages/prerelease-packages.md)
417+
- [Set package type](../create-packages/set-package-type.md)
418+
- [Create packages with COM interop assemblies](../create-packages/author-packages-with-COM-interop-assemblies.md)
463419
464420
Finally, there are additional package types to be aware of:
465421
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: Create packages with COM interop assemblies
3+
description: Describes how to create packages that contain COM interop assemblies
4+
author: karann-msft
5+
ms.author: karann
6+
ms.date: 07/09/2019
7+
ms.topic: conceptual
8+
---
9+
10+
## Create NuGet packages that contain COM interop assemblies
11+
12+
Packages that contain COM interop assemblies must include an appropriate [targets file](creating-a-package.md#include-msbuild-props-and-targets-in-a-package) so that the correct `EmbedInteropTypes` metadata is added to projects using the PackageReference format. By default, the `EmbedInteropTypes` metadata is always false for all assemblies when PackageReference is used, so the targets file adds this metadata explicitly. To avoid conflicts, the target name should be unique; ideally, use a combination of your package name and the assembly being embedded, replacing the `{InteropAssemblyName}` in the example below with that value. (Also see [NuGet.Samples.Interop](https://github.com/NuGet/Samples/tree/master/NuGet.Samples.Interop) for an example.)
13+
14+
```xml
15+
<Target Name="Embedding**AssemblyName**From**PackageId**" AfterTargets="ResolveReferences" BeforeTargets="FindReferenceAssembliesForReferences">
16+
<ItemGroup>
17+
<ReferencePath Condition=" '%(FileName)' == '{InteropAssemblyName}' AND '%(ReferencePath.NuGetPackageId)' == '$(MSBuildThisFileName)' ">
18+
<EmbedInteropTypes>true</EmbedInteropTypes>
19+
</ReferencePath>
20+
</ItemGroup>
21+
</Target>
22+
```
23+
24+
Note that when using the `packages.config` management format, adding references to the assemblies from the packages causes NuGet and Visual Studio to check for COM interop assemblies and set the `EmbedInteropTypes` to true in the project file. In this case the targets are overriden.
25+
26+
Additionally, by default the [build assets do not flow transitively](../consume-packages/package-references-in-project-files.md#controlling-dependency-assets). Packages authored as described here work differently when they are pulled as a transitive dependency from a project to project reference. The package consumer can allow them to flow by modifying the PrivateAssets default value to not include build.
27+
28+
<a name="creating-the-package"></a>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Set a NuGet package type
3+
description: Describes packages types to indicate intended use of a package.
4+
author: karann-msft
5+
ms.author: karann
6+
ms.date: 07/09/2019
7+
ms.topic: conceptual
8+
---
9+
10+
# Set a NuGet package type
11+
12+
With NuGet 3.5+, packages can be marked with a specific *package type* to indicate its intended use. Packages not marked with a type, including all packages created with earlier versions of NuGet, default to the `Dependency` type.
13+
14+
- `Dependency` type packages add build- or run-time assets to libraries and applications, and can be installed in any project type (assuming they are compatible).
15+
16+
- `DotnetCliTool` type packages are extensions to the [dotnet CLI](/dotnet/articles/core/tools/index) and are invoked from the command line. Such packages can be installed only in .NET Core projects and have no effect on restore operations. More details about these per-project extensions are available in the [.NET Core extensibility](/dotnet/articles/core/tools/extensibility#per-project-based-extensibility) documentation.
17+
18+
- Custom type packages use an arbitrary type identifier that conforms to the same format rules as package IDs. Any type other than `Dependency` and `DotnetCliTool`, however, are not recognized by the NuGet Package Manager in Visual Studio.
19+
20+
Package types are set in the `.nuspec` file. It's best for backwards compatibility to *not* explicitly set the `Dependency` type and to instead rely on NuGet assuming this type when no type is specified.
21+
22+
- `.nuspec`: Indicate the package type within a `packageTypes\packageType` node under the `<metadata>` element:
23+
24+
```xml
25+
<?xml version="1.0" encoding="utf-8"?>
26+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
27+
<metadata>
28+
<!-- ... -->
29+
<packageTypes>
30+
<packageType name="DotnetCliTool" />
31+
</packageTypes>
32+
</metadata>
33+
</package>
34+
```

docs/guides/Create-NET-Standard-Packages-VS2015.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ This guide walks you through creating a NuGet package targeting .NET Standard Li
6363
nuget spec
6464
```
6565

66-
1. Open `AppLogger.nuspec` in an editor and update it to match the following, replacing YOUR_NAME with an appropriate value. The `<id>` value, specifically, must be unique across nuget.org (see the naming conventions described in [Creating a package](../create-packages/creating-a-package.md#choosing-a-unique-package-identifier-and-setting-the-version-number). Also note that you must also update the author and description tags or you get an error during the packing step.
66+
1. Open `AppLogger.nuspec` in an editor and update it to match the following, replacing YOUR_NAME with an appropriate value. The `<id>` value, specifically, must be unique across nuget.org (see the naming conventions described in [Creating a package](../create-packages/creating-a-package.md#choose-a-unique-package-identifier-and-setting-the-version-number). Also note that you must also update the author and description tags or you get an error during the packing step.
6767

6868
```xml
6969
<?xml version="1.0"?>
@@ -162,7 +162,7 @@ Note that `pack` requires Mono 4.4.2 on Mac OS X and does not work on Linux syst
162162

163163
- [.nuspec reference](../reference/nuspec.md)
164164
- [Supporting multiple .NET framework versions](../create-packages/supporting-multiple-target-frameworks.md)
165-
- [Include MSBuild props and targets in a package](../create-packages/creating-a-package.md#including-msbuild-props-and-targets-in-a-package)
165+
- [Include MSBuild props and targets in a package](../create-packages/creating-a-package.md#include-msbuild-props-and-targets-in-a-package)
166166
- [Creating localized packages](../create-packages/creating-localized-packages.md)
167167
- [Symbol packages](../create-packages/symbol-packages.md)
168168
- [Package versioning](../reference/package-versioning.md)

0 commit comments

Comments
 (0)