Skip to content

Commit f1742a1

Browse files
author
Kraig Brockschmidt
authored
Merge pull request NuGet#162 from NuGet/kraigb
Adding more code tags and other corrections
2 parents ff909a4 + 3117e06 commit f1742a1

21 files changed

+173
-42
lines changed

docs/Consume-Packages/Configuring-NuGet-Behavior.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ The preferred method for changing the configuration is using the NuGet [config c
6363
6464
To **set a value** in any existing configuration file, use the `-configFile` switch as shown in the examples below.
6565

66+
```bash
6667
nuget config -set repositoryPath=c:\packages -configfile c:\my.config
6768
nuget config -set repositoryPath=c:\packages -configfile .\myApp\NuGet.Config
6869
nuget config -set repositoryPath=c:\packages -configfile %ProgramData%\NuGet\Config\VisualStudio\14.0\NuGet.Config
6970
nuget config -set repositoryPath=c:\packages -configfile %ProgramData%\NuGet\NuGetDefaults.Config
71+
```
7072

7173
Without the `-configFile` switch, NuGet will make the change in the global config file.
7274

@@ -75,7 +77,9 @@ Without the `-configFile` switch, NuGet will make the change in the global confi
7577
7678
To **remove a value**, use the same commands but with an empty value, such as:
7779

80+
```bash
7881
nuget config -set repositoryPath= -configfile c:\my.config
82+
```
7983

8084
To create a new configuration file, copy the template below into that file and then use the `nuget config --configFile <filename>` command to set values:
8185

docs/Consume-Packages/Managing-the-NuGet-Cache.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,26 @@ NuGet manages several local caches to avoid downloading packages that are alread
3535

3636
To see the list of cache locations, use the [locals command](../tools/nuget.exe-cli-reference.md#locals):
3737

38+
```bash
3839
nuget locals all -list
40+
```
3941

4042
Typical output is as follows:
4143

42-
http-cache: C:\Users\kraigb\AppData\Local\NuGet\v3-cache #3.x cache
43-
packages-cache: C:\Users\kraigb\AppData\Local\NuGet\Cache #2.x cache
44-
global-packages: C:\Users\kraigb\.nuget\packages\ #Global cache
45-
temp: C:\Users\kraigb\AppData\Local\Temp\NuGetScratch #Temp folder
44+
http-cache: C:\Users\user\AppData\Local\NuGet\v3-cache #3.x cache
45+
packages-cache: C:\Users\user\AppData\Local\NuGet\Cache #2.x cache
46+
global-packages: C:\Users\user\.nuget\packages\ #Global cache
47+
temp: C:\Users\user\AppData\Local\Temp\NuGetScratch #Temp folder
4648

4749
If you encounter package installation problems or otherwise want to ensure that you're installing packages from the remote gallery, use the `locals -clear` option in one or more of the following ways:
4850

51+
```bash
4952
nuget locals http-cache -clear #Clear the 3.x cache
5053
nuget locals packages-cache -clear #Clear the 2.x cache
5154
nuget locals global-packages -clear #Clear the global cache
5255
nuget locals temp -clear #Clear the temporary cache
5356
nuget locals all -clear #Clears all caches
57+
```
5458

5559
Note that managing the cache is presently supported only from the NuGet command line, and not within Visual Studio or through the Package Manager Console. Also, managing the 2.x cache is not supported in NuGet 3.6 and later.
5660

docs/Consume-Packages/Package-References-in-Project-Files.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,25 @@ You might be using a dependency purely as a development harness and might not wa
110110

111111
The following metadata tags control dependency assets:
112112

113-
| Tag | Description | Default Value
114-
| IncludeAssets | These assets will be consumed | all
115-
| ExcludeAssetsTag | These assets will not be consumed | none
116-
| PrivateAssets | These assets will be consumed but won't flow to the parent project | contentfiles;analyzers;build
113+
Tag | Description | Default Value
114+
--- | --- | ---
115+
IncludeAssets | These assets will be consumed | all
116+
ExcludeAssetsTag | These assets will not be consumed | none
117+
PrivateAssets | These assets will be consumed but won't flow to the parent project | contentfiles;analyzers;build
117118

118119

119120
Allowable values for these tags are as follows, with multiple values separated by a semicolon except with `all` and `none` which must appear by themselves:
120121

121-
| Value | Description
122-
| compile | Contents of the `lib` folder
123-
| runtime | Contents of the `runtime` folder
124-
| contentFiles | Contents of the `contentfiles` folder
125-
| build | Props and targets in the `build` folder
126-
| anaylzers | .NET analyzers
127-
| native | Contents of the `native` folder
128-
| none | None of the above are used.
129-
| all | All of the above (except `none`)
122+
Value | Description
123+
--- | ---
124+
compile | Contents of the `lib` folder
125+
runtime | Contents of the `runtime` folder
126+
contentFiles | Contents of the `contentfiles` folder
127+
build | Props and targets in the `build` folder
128+
anaylzers | .NET analyzers
129+
native | Contents of the `native` folder
130+
none | None of the above are used.
131+
all | All of the above (except `none`)
130132

131133
In the following example, everything except the content files from the package would be consumed by the project and everything except content files and analyzers would flow to the parent project.
132134

docs/Consume-Packages/Package-Restore.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ For NuGet 2.6 and earlier, you use the [Install](../tools/nuget.exe-cli-referenc
118118

119119
For NuGet 2.7 and above, use the [Restore](../tools/nuget.exe-cli-reference.md#restore) command to restore all packages in a solution (using either `packages.config` in NuGet 2.x and later or `project.json` in NuGet 3.x and later). For a given project folder such as `c:\proj\app`, the common variations below each restore the packages:
120120

121+
```bash
121122
c:\proj\app\> nuget restore
122123
c:\proj\app\> nuget.exe restore app.sln
123124
c:\proj\> nuget restore app
125+
```
124126

125127
## Automatic restore in Visual Studio
126128

@@ -149,8 +151,10 @@ To correct these errors, do one of the following:
149151
1. [Migrate the project to automatic restore](#migrating-to-automatic-restore).
150152
1. Update `nuget.exe` in the `.nuget` folder** as follows
151153

154+
```bash
152155
cd .nuget
153156
nuget update -self
157+
```
154158

155159
1. Reset consent in your `%AppData%\NuGet\NuGet.config` file by going to **Tools > Options > NuGet Package Manager > General** in Visual Studio, uncheck and re-check both **Package Restore** options, and click OK. This re-saves `NuGet.config` with the proper consent settings for NuGet 2.6 and earlier.
156160

docs/Consume-Packages/Team-Foundation-Build.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ NuGet has supported [restoring packages](../consume-packages/package-restore.md)
5252

5353
The cure to this problem is making sure that packages are restored as the first step in the build process. NuGet 2.7+ makes this easy via a simplified command line:
5454

55+
```bash
5556
nuget restore path\to\solution.sln
57+
```
5658

5759
When your build process restores packages before building the code, you don't need to check-in **.targets** files
5860

docs/Create-Packages/Creating-a-Package.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ For details on declaring dependencies and specifying version numbers, see [Depen
128128

129129
Because the manifest is always included in a package, you can find any number of additional examples by examining existing packages. A good source is the global package cache on your machine, the location of which is returned by the following command:
130130

131+
```bash
131132
nuget locals -list global-packages
133+
```
132134

133135
Go into any *package\version* folder, copy the .nupkg file to a .zip file, then open that .zip file and examine the .nuspec within it.
134136

@@ -139,7 +141,9 @@ Note that when creating a `.nuspec` from a Visual Studio project, the manifest w
139141

140142
You can create a `.nuspec` file from scratch in any text editor, or by editing a file from another project. You can also have NuGet create a template manifest for your by using the following command:
141143

144+
```bash
142145
nuget spec <package_name>
146+
```
143147

144148
The resulting `<package_name>.nuspec` file (or `Package.nuspec` if you omit a specific name) will contain placeholders for values like the `projectUrl`, so be sure to edit it before using it to creating the package.
145149

@@ -149,13 +153,17 @@ You can also use `nuget spec` with an existing assembly, a Visual Studio project
149153

150154
If you have an assembly DLL, you can easily generate a `.nuspec` file from the metadata in the assembly using the following command:
151155

156+
```bash
152157
nuget spec MyAssembly.dll
158+
```
153159

154160
### From a Visual Studio project
155161

156162
Creating a `.nuspec` from a `.csproj` or `.vbproj` file is convenient because other packages that have been installed into those project will be automatically referenced as dependencies. Simply use the following command in the same folder as the project file:
157163

164+
```bash
158165
nuget spec
166+
```
159167

160168
This creates a template `<project_name>.nuspec` file as usual, but includes tokens that will be replaced at packaging time with values from the project. This means you do not need to update crucial values like the version number in the `.nuspec` as you update the project (but you can always replace the tokens with literal values, if desired).
161169

@@ -200,7 +208,9 @@ Think of the **content** folder as the root of the target application, so if you
200208

201209
Next, from the root folder of this layout, run the following command to create the `.nuspec` file:
202210

211+
```bash
203212
nuget spec
213+
```
204214

205215
In this case, the `.nuspec` will not contain any explicit references to the folder structure, but all those files will be automatically included when creating the package later on.
206216

@@ -333,11 +343,15 @@ With NuGet 3.x, targets are not added to the project but are instead made availa
333343

334344
When using an assembly or the convention-based working directory, create a package by running `nuget pack` with your `.nuspec` file:
335345

346+
```bash
336347
nuget pack &lt;your_project&gt;.nuspec
348+
```
337349

338350
When using a Visual Studio project, run `nuget pack` instead with your project file, which will automatically load the project's `.nuspec` file and replace any tokens within it using values in the project file:
339351

352+
```bash
340353
nuget pack &lt;your_project&gt;.csproj
354+
```
341355

342356
> [!Note]
343357
> Using the project file directly is necessary for token replacement because the project is the source of the token values. Token replacement does not happen if you use `nuget pack` with a `.nuspec` file.
@@ -361,20 +375,26 @@ The following options are a few that are common with Visual Studio projects:
361375

362376
- **Referenced projects**: If the project references other projects, you can add the referenced projects as part of the package, or as dependencies, by using the `-IncludeReferencedProjects` option:
363377

378+
```bash
364379
nuget pack MyProject.csproj -IncludeReferencedProjects
380+
```
365381

366382
This inclusion process is recursive, so if MyProject.csproj references projects B and C, and those projects reference D, E, and F, then files from B, C, D, E, and F will be included in the package.
367383

368384
If a referenced project includes a `.nuspec` file of its own, then NuGet adds that referenced project as a dependency instead. You will need to package and publish that project separately.
369385

370386
- **Build configuration**: By default, NuGet will use the default build configuration set in the project file, typically *Debug*. To pack files from a different build configuration, such as *Release*, use the `-properties` option with the configuration:
371387

388+
```bash
372389
nuget pack MyProject.csproj -properties Configuration=Release
390+
```
373391

374392
- **Symbols**: to include symbols that allow consumers to step through your package code in the debugger, use the `-Symbols` option:
375393

394+
```bash
376395
nuget pack MyProject.csproj -symbols
377-
396+
```
397+
378398
## Next Steps
379399

380400
Once you've created a package, which is a `.nupkg` file, you can publish it to the gallery of your choice as described on [Publishing a Package](../create-packages/publish-a-package.md).

docs/Create-Packages/Publish-a-package.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@ Next, you can either upload the package through the nuget.org web portal, or pus
5454

5555
3. At a command prompt, run the following command:
5656

57+
```bash
5758
nuget setApiKey Your-API-Key
59+
```
5860

5961
This will store your API key on the machine so that you will not need to do this step again on the same machine.
6062

6163
4. Push your package to NuGet Gallery using the command:
6264

65+
```bash
6366
nuget push YourPackage.nupkg -Source https://www.nuget.org/api/v2/package
67+
```
6468

6569
5. Before being made public, all packages uploaded to nuget.org are scanned for viruses and rejected if any viruses are found. All packages listed on nuget.org are also scanned periodically.
6670

docs/Create-Packages/Symbol-Packages.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ To create a symbol package, follow these conventions:
4343

4444
You can create both packages with the `-Symbols` option, either from a nuspec file or a project file:
4545

46+
```bash
4647
nuget pack MyPackage.nuspec -Symbols
4748

4849
nuget pack MyProject.csproj -Symbols
50+
```
4951

5052
Note that `pack` requires Mono 4.4.2 on Mac OS X and does not work on Linux systems. On a Mac, you must also convert Windows pathnames in the `.nuspec` file to Unix-style paths.
5153

@@ -110,18 +112,26 @@ A symbol package can be built by conventions, from a folder structure as describ
110112

111113
1. For convenience, first save your API key with NuGet (see [publish a package](../create-packages/publish-a-package.md), which will apply to both nuget.org and symbolsource.org, because symbolsource.org will check with nuget.org to verify that you are the package owner.
112114

115+
```bash
113116
nuget SetApiKey Your-API-Key
117+
```
114118

115119
1. After publishing your primary package to nuget.org, push the symbol package as follows, which will automatically use symbolsource.org as the target because of the `.symbols` in the filename:
116120

121+
```bash
117122
nuget push MyPackage.symbols.nupkg
123+
```
118124

119125
1. To publish to a different symbol repository, or to push a symbol package that doesn't follow the naming convention, use the `-Source` option:
120126

127+
```bash
121128
nuget push MyPackage.symbols.nupkg -source https://nuget.smbsrc.net/
129+
```
122130

123131
1. You can also push both primary and symbol packages to both repositories at the same time using the following:
124132

133+
```bash
125134
nuget push MyPackage.nupkg
135+
```
126136

127137
In this case, NuGet will publish `MyPackage.symbols.nupkg`, if present, to symbolsource.org (https://nuget.smbsrc.net/), after it publishes the primary package to nuget.org.

docs/Create-Packages/project.json-and-UWP.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ NuGet packages using the new format have the following well-known directories an
8585

8686
## MSBuild targets and props files in packages
8787

88-
NuGet packages can contain .props and .targets files which will be imported into any MSBuild project that the package is installed into. In NuGet 2.x, this was done by injecting &lt;Import&gt; statements into the .csproj file, in NuGet 3.0 there is no specific "installation to project" action. Instead the package restore process writes two files:
89-
90-
* [projectname].nuget.props
91-
92-
* [projectname].nuget.targets
88+
NuGet packages can contain .props and .targets files which will be imported into any MSBuild project that the package is installed into. In NuGet 2.x, this was done by injecting &lt;Import&gt; statements into the .csproj file, in NuGet 3.0 there is no specific "installation to project" action. Instead the package restore process writes two files `[projectname].nuget.props` and `[projectname].nuget.targets`.
9389

9490
MSBuild knows to look for these two files and automatically imports them near the beginning and near the end of the project build process. This provides very similar behavior to NuGet 2, but with one major difference: **There is no guaranteed order of targets/props files in this case**. However, MSBuild does provide ways to order Targets through the BeforeTargets and AfterTargets attributes of the &lt;Target&gt; definition (see [https://msdn.microsoft.com/en-us/library/t50z2hka.aspx](https://msdn.microsoft.com/en-us/library/t50z2hka.aspx)).
9591

docs/Guides/Create-Cross-Platform-Packages.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ To implement a platform-specific implementation of the `ILoggingLibrary` interfa
124124

125125
1. Open a command prompt, navigate to the `LoggingLibrary` folder that's one level below where the .sln file is, and run the NuGet `spec` command to create the initial `Package.nuspec` file:
126126

127+
```bash
127128
nuget spec
129+
```
128130

129131
1. Rename this file to `LoggingLibrary.nuspec` and open it in an editor.
130132
1. Update the file to match the following, replacing YOUR_NAME with an appropriate value. The &lt;id&gt; 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'll get an error during the packing step.
@@ -263,7 +265,9 @@ Your final .nuspec file should now look like the following, where again YOUR_NAM
263265

264266
With the completed .nuspec referencing all the files you need to include in the package, you're ready to run the `pack` command:
265267

268+
```bash
266269
nuget pack LoggingLibrary.nuspec
270+
```
267271

268272
This will generate `LoggingLibrary.YOUR_NAME.1.0.0.nupkg`. Opening this file in a tool like the [NuGet Package Explorer](https://github.com/NuGetPackageExplorer/NuGetPackageExplorer) and expanding all the nodes, you'll see the following contents:
269273

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ This guide will walk you through creating a nuget package targeting .NET Standar
8989

9090
1. Open a command prompt, navigate to the folder containing `AppLogg.csproj` folder (one level below where the .sln file is), and run the NuGet `spec` command to create the initial `AppLogger.nuspec` file:
9191

92+
```bash
9293
nuget spec
94+
```
9395

9496
1. Open `AppLogger.nuspec` in an editor and update it to match the following, replacing YOUR_NAME with an appropriate value. The &lt;id&gt; 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'll get an error during the packing step.
9597

@@ -128,7 +130,9 @@ This guide will walk you through creating a nuget package targeting .NET Standar
128130

129131
With the completed .nuspec referencing all the files you need to include in the package, you're ready to run the `pack` command:
130132

133+
```bash
131134
nuget pack AppLogger.nuspec
135+
```
132136

133137
This will generate `AppLogger.YOUR_NAME.1.0.0.nupkg`. Opening this file in a tool like the [NuGet Package Explorer](https://github.com/NuGetPackageExplorer/NuGetPackageExplorer) and expanding all the nodes, you'll see the following contents:
134138

docs/Guides/Create-UWP-Packages.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ To create the initial .nuspec file, do the three steps below. The sections that
8080
1. Open a command prompt and navigate to the folder containing ImageEnhancer.vcxproj (this will be a subfolder below where the solution file is).
8181
1. Run the NuGet `spec` command to generate `ImageEnhancer.nuspec` (the name of the file is taken from the name of the .vcxproj file):
8282

83+
```bash
8384
nuget spec
85+
```
8486

8587
1. Open `ImageEnhancer.nuspec` in an editor and update it to match the following, replacing YOUR_NAME with an appropriate value. The &lt;id&gt; 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'll get an error during the packing step.
8688
@@ -259,7 +261,9 @@ Your final .nuspec file should now look like the following, where again YOUR_NAM
259261
260262
With the completed .nuspec referencing all the files you need to include in the package, you're ready to run the `pack` command:
261263

264+
```bash
262265
nuget pack ImageEnhancer.nuspec
266+
```
263267

264268
This will generate `ImageEnhancer.YOUR_NAME.1.0.0.nupkg`. Opening this file in a tool like the [NuGet Package Explorer](https://github.com/NuGetPackageExplorer/NuGetPackageExplorer) and expanding all the nodes, you'll see the following contents:
265269

docs/Guides/Install-NuGet.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ The NuGet CLI can be installed using any of the following methods:
7070

7171
1. **Chocolatey**: Install the [NuGet.CommandLine](http://chocolatey.org/packages/NuGet.CommandLine) Chocolatey package using the [Chocolatey](http://chocolatey.org) client.
7272

73+
```bash
7374
choco install nuget.commandline
74-
75+
```
76+
7577
1. **Visual Studio**: Install the [NuGet.CommandLine](http://www.nuget.org/packages/NuGet.CommandLine/) package from the Package Manager Console in Visual Studio.
7678

7779
> **NuGet 2.x users**

0 commit comments

Comments
 (0)