Skip to content

Commit 661d84f

Browse files
author
John Stallo
committed
how to use custom NuGet feeds
1 parent 7d454ed commit 661d84f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Use a custom NuGet feed
2+
3+
A NuGet feed provides a convenient way to include package sources in a project. Connected Environment will need to be able to access this feed in order dependencies to be properly installed in the Docker container.
4+
5+
To set up a NuGet feed:
6+
1. Add a [package reference](https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files) in the `*.csproj` file under the `PackageReference` node.
7+
8+
```xml
9+
<ItemGroup>
10+
<!-- ... -->
11+
<PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0" />
12+
<!-- ... -->
13+
</ItemGroup>
14+
```
15+
16+
2. Create a [NuGet.Config](https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file) file in the project folder.
17+
* Use the `packageSources` section to reference your NuGet feed location. Important: The NuGet feed must be publicly accessible.
18+
* Use the `packageSourceCredentials` section to configure username and password credentials.
19+
20+
```xml
21+
<packageSources>
22+
<add key="Contoso" value="https://contoso.com/packages/" />
23+
</packageSources>
24+
25+
<packageSourceCredentials>
26+
<Contoso>
27+
<add key="Username" value="[email protected]" />
28+
<add key="ClearTextPassword" value="33f!!lloppa" />
29+
</Contoso>
30+
</packageSourceCredentials>
31+
```
32+
33+
3. If you're using source code control:
34+
- Reference `NuGet.Config` in your `.gitignore` file so you don't accidentally commit credentials to your source repository.
35+
- Open the `vsce.yaml` file in your project, and locate the `build` section, and insert the following snippet to ensure that the `NuGet.Config` file will be synced to Azure so that it used during the container image build process. (By default, Connected Environment does not synchronize files that match `.gitignore` and `.dockerignore` rules.)
36+
37+
```yaml
38+
build:
39+
useGitIgnore: true
40+
ignore:
41+
- “!NuGet.Config”
42+
```
43+
44+
45+
Once you have completed the above steps, the next time you run `vsce up` (or hit `F5` in VSCode or Visual Studio), Connected Environment will synchronize the `NuGet.Config` file to Azure, which is then utilized by `dotnet restore` to install package dependencies in the container.
46+

0 commit comments

Comments
 (0)