|
| 1 | +--- |
| 2 | +title: "How to use a custom NuGet feed in a connected environment| Microsoft Docs" |
| 3 | +author: "johnsta" |
| 4 | +ms.author: "johnsta" |
| 5 | +ms.date: "03/27/2018" |
| 6 | +ms.topic: "article" |
| 7 | +description: "Use a custom NuGet feed to access and use NuGet packages in a connected environment." |
| 8 | +keywords: "Docker, Kubernetes, Azure, AKS, Azure Container Service, containers" |
| 9 | +manager: "ghogen" |
| 10 | +--- |
| 11 | +# Use a custom NuGet feed in a connected environment |
| 12 | + |
| 13 | +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 for dependencies to be properly installed in the Docker container. |
| 14 | + |
| 15 | +To set up a NuGet feed: |
| 16 | +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. |
| 17 | + |
| 18 | + ```xml |
| 19 | + <ItemGroup> |
| 20 | + <!-- ... --> |
| 21 | + <PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0" /> |
| 22 | + <!-- ... --> |
| 23 | + </ItemGroup> |
| 24 | + ``` |
| 25 | + |
| 26 | +2. Create a [NuGet.Config](https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file) file in the project folder. |
| 27 | + * Use the `packageSources` section to reference your NuGet feed location. Important: The NuGet feed must be publicly accessible. |
| 28 | + * Use the `packageSourceCredentials` section to configure username and password credentials. |
| 29 | + |
| 30 | + ```xml |
| 31 | + <packageSources> |
| 32 | + <add key="Contoso" value="https://contoso.com/packages/" /> |
| 33 | + </packageSources> |
| 34 | + |
| 35 | + <packageSourceCredentials> |
| 36 | + <Contoso> |
| 37 | + < add key= "Username" value= "[email protected]" /> |
| 38 | + <add key="ClearTextPassword" value="33f!!lloppa" /> |
| 39 | + </Contoso> |
| 40 | + </packageSourceCredentials> |
| 41 | + ``` |
| 42 | + |
| 43 | +3. If you're using source code control: |
| 44 | + - Reference `NuGet.Config` in your `.gitignore` file so you don't accidentally commit credentials to your source repository. |
| 45 | + - 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.) |
| 46 | + |
| 47 | + ```yaml |
| 48 | + build: |
| 49 | + useGitIgnore: true |
| 50 | + ignore: |
| 51 | + - “!NuGet.Config” |
| 52 | + ``` |
| 53 | +
|
| 54 | +
|
| 55 | +## Next steps |
| 56 | +
|
| 57 | +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. |
| 58 | + |
0 commit comments