

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在 Visual Studio 中使用 CodeArtifact
<a name="using-aws-codeartifact"></a>

AWS CodeArtifact 是一项完全托管的构件存储库服务，可让组织轻松安全地存储和共享用于应用程序开发的软件包。您可以将 CodeArtifact 与常用的构建工具和程序包管理器配合使用，例如 NuGet 和.NET Core CLI 以及 Visual Studio。您还可以将 CodeArtifact 配置为从外部公共存储库（例如 [NuGet.org](https://www.nuget.org/)）提取程序包。

在 CodeArtifact 中，您的程序包存储在存储库中，而后者存储在域中。AWS Toolkit for Visual Studio 简化了 Visual Studio 使用 CodeArtifact 存储库时的配置，从而可以轻松地在 Visual Studio 中直接使用 CodeArtifact 和 Nuget.org 中的程序包。

## 将您的 CodeArtifact 存储库添加为 NuGet 程序包来源
<a name="add-repo-as-nuget-package-source"></a>

要使用来自 CodeArtifact 的程序包，您需要在 Visual Studio 的 **NuGet Package Manager** 中将存储库作为可打包来源添加

 **将您的存储库添加为程序包来源** 

1. 在 AWS 各区服务浏览器中，导航到 **AWS CodeArtifact** 节点中的存储库。

1. 打开要添加的存储库的上下文（右键单击）菜单，然后选择**复制 NuGet 来源端点**。

1. 在**工具 > 选项**菜单中，导航到 **NuGet Package Manager** 节点下的**程序包来源**。

1. 在**程序包来源**中，选择加号（**\$1**），编辑名称，然后将之前复制的 NuGet 来源端点 URL 粘贴到**来源**字段中。

1. 选中新添加的程序包来源旁的复选框以启用该来源。
**注意**  
我们建议在 CodeArtifact 中添加指向 **NuGet.org** 的外部连接，并在 Visual Studio 中禁用 **nuget.org** 程序包来源。使用外部连接时，从 **NuGet.org** 提取的所有依赖项都存储在 CodeArtifact 中。如果 **NuGet.org** 因任何原因出现故障，您需要的程序包仍然可用。有关外部连接的更多信息，请参阅《AWS CodeArtifact User Guide》**中的 [Add an external connection](https://docs.aws.amazon.com/codeartifact/latest/ug/external-connection.html)。

1. 选择**确定**以关闭菜单。

有关将 CodeArtifact 与 Visual Studio 配合使用的更多信息，请参阅《AWS CodeArtifact User Guide》**中的 [Use CodeArtifact with Visual Studio](https://docs.aws.amazon.com/codeartifact/latest/ug/nuget-visual-studio.html)。