Skip to content

Commit c3f65a0

Browse files
author
Kraig Brockschmidt
authored
Merge pull request NuGet#157 from NuGet/kraigb
Mark code languages for issue 146
2 parents 9e942f6 + 72d6556 commit c3f65a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+405
-44
lines changed

docs/API/NuGet-Credential-Providers-for-Visual-Studio.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ During credential acquisition, the credential service will try credential provid
6565

6666
To create a NuGet credential provider for Visual Studio, create a Visual Studio Extension that exposes a public MEF Export implementing the `IVsCredentialProvider` type, and adheres to the principles outlined below.
6767

68+
```cs
6869
public interface IVsCredentialProvider
6970
{
7071
Task<ICredentials> GetCredentialsAsync(
@@ -75,6 +76,7 @@ To create a NuGet credential provider for Visual Studio, create a Visual Studio
7576
bool nonInteractive,
7677
CancellationToken cancellationToken);
7778
}
79+
```
7880

7981
A sample implementation can be found in [the VsCredentialProvider sample](https://github.com/NuGet/Samples/tree/master/VsCredentialProvider).
8082

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ To **remove a value**, use the same commands but with an empty value, such as:
7979

8080
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:
8181

82+
```xml
8283
<?xml version="1.0" encoding="utf-8"?>
8384
<configuration>
8485
</configuration>
86+
```
8587

8688
> [!Warning]
8789
> Although you can modify the file in any text editor, NuGet (v3.4.3 and later) silently ignores the entire configuration file if it contains malformed XML (mismatched tags, invalid quotation marks, etc.).
@@ -153,15 +155,18 @@ You then have four `NuGet.Config` files in the following locations with the give
153155

154156
1. Global configuration file, `%APPDATA%\NuGet\Nuget.config`:
155157

158+
```xml
156159
<?xml version="1.0" encoding="utf-8"?>
157160
<configuration>
158161
<activePackageSource>
159162
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
160163
</activePackageSource>
161164
</configuration>
165+
```
162166

163167
1. `d:\NuGet.config`:
164168

169+
```xml
165170
<?xml version="1.0" encoding="utf-8"?>
166171
<configuration>
167172
<config>
@@ -171,9 +176,11 @@ You then have four `NuGet.Config` files in the following locations with the give
171176
<add key="enabled" value="True" />
172177
</packageRestore>
173178
</configuration>
179+
```
174180

175181
1. `d:\Project1\NuGet.config`:
176182

183+
```xml
177184
<?xml version="1.0" encoding="utf-8"?>
178185
<configuration>
179186
<config>
@@ -185,16 +192,19 @@ You then have four `NuGet.Config` files in the following locations with the give
185192
<add key="MyPrivateRepo - ES" value="https://MyPrivateRepo/ES/nuget" />
186193
</packageSources>
187194
</configuration>
195+
```
188196

189197
1. `d:\Project2\NuGet.config`:
190198

199+
```xml
191200
<?xml version="1.0" encoding="utf-8"?>
192201
<configuration>
193202
<packageSources>
194203
<!-- Add this repository to the list of available repositories -->
195204
<add key="MyPrivateRepo - DQ" value="https://MyPrivateRepo/DQ/nuget" />
196205
</packageSources>
197206
</configuration>
207+
```
198208

199209
Here's how NuGet will load and apply the settings, depending on where it's invoked:
200210

@@ -227,6 +237,7 @@ The defaults file works with the following settings:
227237

228238
The following is an example NuGetDefaults.config file containing each of its allowable sections:
229239

240+
```xml
230241
<?xml version="1.0" encoding="UTF-8"?>
231242
<configuration>
232243
<!-- DefaultPushSource key is similar to the 'DefaultPushSource' key of NuGet.config schema-->
@@ -251,3 +262,4 @@ The following is an example NuGetDefaults.config file containing each of its all
251262
<add key="nuget.org" value="true" />
252263
</disabledPackageSources>
253264
</configuration>
265+
```

docs/Consume-Packages/Dependency-Resolution.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ The lock file is temporary and does not need to be added to source control; it's
7979

8080
NuGet 3.x applies four main rules to resolve dependencies: lowest applicable version, floating versions, nearest-wins, cousin dependencies.
8181

82-
#### Lowest applicable version
8382
<a name="lowest-applicable-version"></a>
8483

84+
#### Lowest applicable version
85+
8586
NuGet 3.x restores the lowest possible version of a package as defined by its dependencies. This rule also applied to dependencies on the application or the class library unless declared as [floating](#floating-versions).
8687

8788
For example, in the following figure *1.0-Beta* is considered lower than *1.0* so NuGet chooses the 1.0 version:
@@ -96,18 +97,19 @@ When an application specifies an exact version number, such as *1.2*, that is no
9697

9798
![NuGet generates an error when an exact package version is not available](media/projectJson-dependency-3.png)
9899

99-
#### Floating versions
100100
<a name="floating-versions"></a>
101101

102+
#### Floating versions
103+
102104
A floating dependency version is specified with the * wildcard, as with *6.0.\** in the `project.json` file. This says "use the latest 6.0.x version"; a floating version of *4.\** means "use the latest 4.x version." Using a floating version allows a dependency package to continue evolving without requiring a change to the consuming application (or package).
103105

104106
When a floating version constraint is specified then NuGet will resolve the highest version of a package that matches the version pattern, for example *6.0.** will get the highest version of a package that starts with *6.0*:
105107

106108
![Choosing version 6.0.1 when a floating version 6.0.* is requested](media/projectJson-dependency-4.png)
107109

110+
<a name="nearest-wins"></a>
108111

109112
#### Nearest wins
110-
<a name="nearest-wins"></a>
111113

112114
When the package graph for an application contains different versions of the same package, the package that's closest to the application in the graph will be used and others will be ignored. This allows an application to override any particular package version in the dependency graph.
113115

@@ -122,9 +124,10 @@ This rule also results in greater efficiency with large dependency graph (such a
122124

123125
![When NuGet ignores a package in the graph, it ignores that entire branch](media/projectJson-dependency-6.png)
124126

125-
#### Cousin dependencies
126127
<a name="cousin-dependencies"></a>
127128

129+
#### Cousin dependencies
130+
128131
When different package versions are referred to at the same distance in the graph from the application, NuGet uses the lowest version that satisfies all version requirements (as with the [lowest applicable version](#lowest-applicable-version) and [floating versions](#floating-versions) rules). In the image below, for example, version *2.0* of Package B will satisfy the other *>=1.0* constraint, and will thus be used:
129132

130133
![Resolving cousin dependencies using the lower version that satisfies all constraints](media/projectJson-dependency-7.png)

docs/Consume-Packages/Finding-and-Choosing-Packages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ You can also search using the package ID, if you know it. See [Search Syntax](#s
5252

5353
At this time, search results are sorted only by relevance, so you generally want to look through at least the first few pages of results for packages that suit your needs, or refine your search terms to be more specific.
5454

55+
<a name="native-c++-packages"></a>
5556

5657
### Native C++ packages
57-
<a name="native-c++-packages"></a>
5858

5959
NuGet 2.5+ supports native C++ packages can that can be used in C++ projects in Visual Studio. This enables the **Manage NuGet Packages** context-menu command for projects, introduces a `native` target framework, and provides MSBuild integration.
6060

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,40 +38,47 @@ Package references, using the `PackageReference` node, allow you to manage NuGet
3838

3939
You can add a dependency in your project file using the following syntax:
4040

41+
```xml
4142
<ItemGroup>
4243
<!-- ... -->
4344
<PackageReference Include="Contoso.Utility.UsefulStuff">
4445
<Version>3.6.0</Version>
4546
</PackageReference>
4647
<!-- ... -->
4748
</ItemGroup>
49+
```
4850

4951
or, alternately:
5052

53+
```xml
5154
<ItemGroup>
5255
<!-- ... -->
5356
<PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0" />
5457
<!-- ... -->
5558
</ItemGroup>
59+
```
5660

5761
## Controlling dependency version
5862

5963
The convention for specifying version remains unchanged:
6064

65+
```xml
6166
<ItemGroup>
6267
<!-- ... -->
6368
<PackageReference Include="Contoso.Utility.UsefulStuff">
6469
<Version>3.6.0</Version>
6570
</PackageReference>
6671
<!-- ... -->
6772
</ItemGroup>
73+
```
6874

6975
In the example above, 3.6.0 means any version that is >=3.6.0 with preference for the lowest version, as described on [version ranges](../create-packages/dependency-versions.md#version-ranges).
7076

7177
## Floating Versions
7278

7379
[Floating versions](../consume-packages/dependency-resolution.md#floating-versions) are supported with `PackageReference`:
7480

81+
```xml
7582
<ItemGroup>
7683
<!-- ... -->
7784
<PackageReference Include="Contoso.Utility.UsefulStuff">
@@ -83,11 +90,13 @@ In the example above, 3.6.0 means any version that is >=3.6.0 with preference fo
8390
</PackageReference>
8491
<!-- ... -->
8592
</ItemGroup>
93+
```
8694

8795
## Controlling dependency assets
8896

8997
You might be using a dependency purely as a development harness and might not want to expose that to projects that will consume your package. In this scenario, you can use the `PrivateAssets` metadata to control this behavior.
9098

99+
```xml
91100
<ItemGroup>
92101
<!-- ... -->
93102

@@ -97,6 +106,7 @@ You might be using a dependency purely as a development harness and might not wa
97106

98107
<!-- ... -->
99108
</ItemGroup>
109+
```
100110

101111
The following metadata tags control dependency assets:
102112

@@ -120,6 +130,7 @@ Allowable values for these tags are as follows, with multiple values separated b
120130

121131
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.
122132

133+
```xml
123134
<ItemGroup>
124135
<!-- ... -->
125136

@@ -131,6 +142,7 @@ In the following example, everything except the content files from the package w
131142

132143
<!-- ... -->
133144
</ItemGroup>
145+
```
134146

135147
Note that because `build` is not included with `PrivateAsset`, targets and props *will* flow to the parent project. Consider, for example, that the reference above is used in a project that builds a NuGet package called AppLogger. AppLogger can consume the targets and props from Contoso.Utility.UsefulStuff, as can projects that consume AppLogger.
136148

@@ -140,20 +152,23 @@ You can use a condition to control whether a package is included, where conditio
140152

141153
For example, say you're targeting `netstandard1.4` as well as `net452` but have a dependency that is applicable only for `net452`. In this case you don't want a `nestandard1.4` project that's consuming your package to add that unnecessary dependency. To prevent this, you specify a condition on the `PackageReference` as follows:
142154

155+
```xml
143156
<ItemGroup>
144157
<!-- ... -->
145158
<PackageReference Include="Newtonsoft.json" Condition="'$(TargetFramework)' == 'net452'">
146159
<Version>9.0.1</Version>
147160
</PackageReference>
148161
<!-- ... -->
149162
</ItemGroup>
163+
```
150164

151165
A package built using this project will show that Newtonsoft.json is included as a dependency only for a `net452` target:
152166

153167
![The result of applying a Condition on PackageReference](media/PackageReference-Condition.png)
154168

155169
Conditions can also be applied at the `ItemGroup` level and will apply to all children `PackageReference` elements:
156170

171+
```xml
157172
<ItemGroup Condition = "'$(TargetFramework)' == 'net452'>
158173
<!-- ... -->
159174

@@ -165,3 +180,4 @@ Conditions can also be applied at the `ItemGroup` level and will apply to all ch
165180

166181
<!-- ... -->
167182
</ItemGroup>
183+
```

docs/Consume-Packages/Package-Restore.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ Package restore is primarily enabled through **Tools > Options > [NuGet] Package
6060

6161
- **Allow NuGet to download missing packages** enables all forms of package restore by changing the `packageRestore/enabled` setting in the `%AppData%\NuGet\NuGet.config` file as shown below. (For NuGet 2.6 or earlier, this setting can also be used in a project-specific `.nuget\nuget.config` file.)
6262

63+
```xml
6364
...
6465
<configuration>
6566
<packageRestore>
6667
<!-- Disables command-line, automatic, and MSBuild-Integrated restore -->
6768
<add key="enabled" value="False" />
6869
</packageRestore>
6970
</configuration>
71+
```
7072

7173

7274
> [!Note]
@@ -75,13 +77,15 @@ Package restore is primarily enabled through **Tools > Options > [NuGet] Package
7577

7678
- **Automatically check for missing packages during build in Visual Studio** enables automatic restore for NuGet 2.7 and later by changing the `packageRestore/automatic` setting in the `%AppData%\NuGet\NuGet.config` file as shown below.
7779

80+
```xml
7881
...
7982
<configuration>
8083
<packageRestore>
8184
<!-- Disables automatic restore in Visual Studio -->
8285
<add key="automatic" value="False" />
8386
</packageRestore>
8487
</configuration>
88+
```
8589

8690
For reference, see the [NuGet config file - packageRestore section](../schema/nuget.config-file.md#packagerestore-section).
8791

@@ -95,11 +99,15 @@ When NuGet restores packages through any method, it will honor any constraints s
9599

96100
- `packages.config`: Specify a version range in the `allowedVersion` property of the dependency. See [Reinstalling and Updating Packages](../consume-packages/reinstalling-and-updating-packages.md#constraining-upgrade-versions). For example:
97101

102+
```xml
98103
<package id="Newtonsoft.json" version="6.0.4" allowedVersions="[6,7)" />
104+
```
99105

100106
- `project.json`: Specify a version range directly with the dependency's version number. For example:
101107

108+
```json
102109
"newtonsoft.json": "[6, 7)"
110+
```
103111

104112
In both cases, use the notation described in [Dependency versions](../create-packages/dependency-versions.md).
105113

@@ -185,6 +193,7 @@ The process is as follows:
185193
a. Remove the `.nuget` folder from the solution and the solution workspace.
186194
1. Edit each project file in the solution, remove the `&lt;RestorePackages&gt;` element, and remove any references to the `nuget.targets` file. Those settings generally appear as follows:
187195

196+
```xml
188197
<RestorePackages>true</RestorePackages>
189198
...
190199
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
@@ -195,6 +204,7 @@ The process is as follows:
195204
</PropertyGroup>
196205
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
197206
</Target>
207+
```
198208

199209
> [!Tip]
200210
> Owen Johnson has created a [PowerShell migration script](https://github.com/owen2/AutomaticPackageRestoreMigrationScript) that can work in many cases, but is used at your own risk. Be sure to commit your project to source control or make a backup before using it.</div>

docs/Consume-Packages/Packages-and-Source-Control.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ To disable source control integration with TFVC for selected files:
7575
1. In that folder, create a file named `NuGet.config` and open it for editing.
7676
1. Add the following text as a minimum, where the [disableSourceControlIntegration](../schema/nuget.config-file.md#solution-section) setting instructs Visual Studio to skip everything in the `packages` folder:
7777

78+
```xml
7879
<?xml version="1.0" encoding="utf-8"?>
7980
<configuration>
8081
<solution>
8182
<add key="disableSourceControlIntegration" value="true" />
8283
</solution>
8384
</configuration>
85+
```
8486

8587
1. If you are using TFS 2010 or earlier, cloak the `packages` folder in your workspace mappings.
8688
1. On TFS 2012 or later, or with Visual Studio Team Services, add a [`.tfignore`](https://msdn.microsoft.com/en-us/library/ms245454.aspx#tfignore) file with the content below to explicitly ignore modifications to the `\packages` folder on the repository level and a few other intermediate files. (You can create the file in Windows Explorer using the name a `.tfignore.` with the trailing dot, but you might need to disable the "Hide known file extensions" option first.):

docs/Consume-Packages/Reinstalling-and-Updating-Packages.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ In projects using `packages.config`, the same behavior applies unless you specif
8383

8484
To set a constraint, open `packages.config` in a text editor, locate the dependency in question, and add the `allowedVersions` attribute with a version range. For example, to constrain updates to version 1.x, set `allowedVersions` to `[1,2)`:
8585

86+
```xml
8687
<?xml version="1.0" encoding="utf-8"?>
8788
<packages>
8889
<package id="ExamplePackage" version="1.1.0" allowedVersions="[1,2)" />
8990

9091
<!-- ... -->
9192
</packages>
93+
```
9294

9395
In all cases, use the notation described in [Dependency versions](../create-packages/dependency-versions.md).

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ The source code is under the `src` folder. Although our demo only uses a single
9999
> [!Note]
100100
> There is currently a [known bug in the NuGet client](https://nuget.codeplex.com/workitem/4072) that causes the client to still add the `packages` folder to version control. A workaround is to disable the source control integration. In order to do that, you'll need a `nuget.config ` file in the `.nuget` folder that is parallel to your solution. If this folder doesn't exist yet, you'll need to create it. In [`nuget.config`](../consume-packages/configuring-nuget-behavior.md), add the following content:
101101
102+
```xml
102103
<configuration>
103104
<solution>
104105
<add key="disableSourceControlIntegration" value="true" />
105106
</solution>
106107
</configuration>
108+
```
107109

108110

109111
In order to communicate to the version control that we don’t intent to check-in the **packages** folders, we've also added ignore files for both git (`.gitignore`) as well as TF version control (`.tfignore`). These files describes patterns of files you don't want to check-in.
@@ -144,6 +146,7 @@ This project will have the three conventional targets `Clean`, `Build` and `Rebu
144146

145147
The result looks as follows:
146148

149+
```xml
147150
<?xml version="1.0" encoding="utf-8"?>
148151
<Project ToolsVersion="4.0"
149152
DefaultTargets="Build"
@@ -181,6 +184,7 @@ The result looks as follows:
181184
Projects="@(Solution)" />
182185
</Target>
183186
</Project>
187+
```
184188

185189
## Configuring Team Build
186190

0 commit comments

Comments
 (0)