选择您的 Cookie 首选项

我们使用必要 Cookie 和类似工具提供我们的网站和服务。我们使用性能 Cookie 收集匿名统计数据,以便我们可以了解客户如何使用我们的网站并进行改进。必要 Cookie 无法停用,但您可以单击“自定义”或“拒绝”来拒绝性能 Cookie。

如果您同意,AWS 和经批准的第三方还将使用 Cookie 提供有用的网站功能、记住您的首选项并显示相关内容,包括相关广告。要接受或拒绝所有非必要 Cookie,请单击“接受”或“拒绝”。要做出更详细的选择,请单击“自定义”。

在中使用 NuGet 软件包 CodeBuild

聚焦模式
在中使用 NuGet 软件包 CodeBuild - CodeArtifact

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

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

以下步骤已使用提供的 Docker 镜像中列出的操作系统进行了测试。 CodeBuild

使用 IAM 角色设置权限

使用中的 NuGet 软件包时,需要执行这些步骤 CodeBuild。 CodeArtifact

  1. 登录 AWS Management Console 并打开 IAM 控制台,网址为https://console.aws.amazon.com/iam/

  2. 在导航窗格中,选择角色。在角色页面上,编辑您的 CodeBuild 构建项目使用的角色。此角色必须具有以下权限。

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codeartifact:GetAuthorizationToken", "codeartifact:GetRepositoryEndpoint", "codeartifact:ReadFromRepository" ], "Resource": "*" }, { "Effect": "Allow", "Action": "sts:GetServiceBearerToken", "Resource": "*", "Condition": { "StringEquals": { "sts:AWSServiceName": "codeartifact.amazonaws.com" } } } ] }
    重要

    如果您还 CodeBuild 想使用发布软件包,请添加codeartifact:PublishPackageVersion权限。

    有关信息,请参阅《IAM 用户指南》中的修改角色

消费 NuGet 包裹

要使用来自的 NuGet 软件包 CodeBuild,请在项目buildspec.yaml文件中包含以下内容。

  1. install在本节中,安装 CodeArtifact 凭据提供程序以配置命令行工具,例如msbuilddotnet以生成和发布软件包。 CodeArtifact

  2. 在该pre-build部分中,将您的 CodeArtifact 存储库添加到您的 NuGet 配置中。

请见以下 buildspec.yaml 示例。有关更多信息,请参阅 CodeArtifact 与一起使用 NuGet

安装凭证提供程序并添加存储库源后,您可以运行该build部分中的 NuGet CLI 工具命令来使用 NuGet 软件包。

Linux

要使用 NuGet 包裹,请使用dotnet以下方法:

version: 0.2 phases: install: runtime-versions: dotnet: latest commands: - export PATH="$PATH:/root/.dotnet/tools" - dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider - dotnet codeartifact-creds install pre_build: commands: - dotnet nuget add source -n codeartifact $(aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format nuget --query repositoryEndpoint --output text)"v3/index.json" build: commands: - dotnet add package <packageName> --source codeartifact

Windows

要使用 NuGet 包裹,请使用dotnet以下方法:

version: 0.2 phases: install: commands: - dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider - dotnet codeartifact-creds install pre_build: commands: - dotnet nuget add source -n codeartifact "$(aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format nuget --query repositoryEndpoint --output text)v3/index.json" build: commands: - dotnet add package <packageName> --source codeartifact

使用 NuGet 软件包构建

要使用来自的 NuGet 包进行构建 CodeBuild,请在项目buildspec.yaml文件中包含以下内容。

  1. install在本节中,安装 CodeArtifact 凭据提供程序以配置命令行工具,例如msbuilddotnet以生成和发布软件包。 CodeArtifact

  2. 在该pre-build部分中,将您的 CodeArtifact 存储库添加到您的 NuGet 配置中。

请见以下 buildspec.yaml 示例。有关更多信息,请参阅 CodeArtifact 与一起使用 NuGet

安装凭证提供程序并添加存储库源后,您可以运行 NuGet CLI 工具命令,如build本节dotnet build所示。

Linux

要使用dotnet以下方法构建 NuGet 软件包:

version: 0.2 phases: install: runtime-versions: dotnet: latest commands: - export PATH="$PATH:/root/.dotnet/tools" - dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider - dotnet codeartifact-creds install pre_build: commands: - dotnet nuget add source -n codeartifact $(aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format nuget --query repositoryEndpoint --output text)"v3/index.json" build: commands: - dotnet build

要使用msbuild以下方法构建 NuGet 软件包:

version: 0.2 phases: install: runtime-versions: dotnet: latest commands: - export PATH="$PATH:/root/.dotnet/tools" - dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider - dotnet codeartifact-creds install pre_build: commands: - dotnet nuget add source -n codeartifact $(aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format nuget --query repositoryEndpoint --output text)"v3/index.json" build: commands: - msbuild -t:Rebuild -p:Configuration=Release

Windows

要使用dotnet以下方法构建 NuGet 软件包:

version: 0.2 phases: install: commands: - dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider - dotnet codeartifact-creds install pre_build: commands: - dotnet nuget add source -n codeartifact "$(aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format nuget --query repositoryEndpoint --output text)v3/index.json" build: commands: - dotnet build

要使用msbuild以下方法构建 NuGet 软件包:

version: 0.2 phases: install: commands: - dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider - dotnet codeartifact-creds install pre_build: commands: - dotnet nuget add source -n codeartifact "$(aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format nuget --query repositoryEndpoint --output text)v3/index.json" build: commands: - msbuild -t:Rebuild -p:Configuration=Release

发布 NuGet 软件包

要从中发布 NuGet 包 CodeBuild,请在项目buildspec.yaml文件中包含以下内容。

  1. install在本节中,安装 CodeArtifact 凭据提供程序以配置命令行工具,例如msbuilddotnet以生成和发布软件包。 CodeArtifact

  2. 在该pre-build部分中,将您的 CodeArtifact 存储库添加到您的 NuGet 配置中。

请见以下 buildspec.yaml 示例。有关更多信息,请参阅 CodeArtifact 与一起使用 NuGet

安装凭证提供程序并添加存储库源后,您可以运行该build部分中的 NuGet CLI 工具命令并发布您的 NuGet 软件包。

Linux

要使用dotnet以下方法发布 NuGet 软件包:

version: 0.2 phases: install: runtime-versions: dotnet: latest commands: - export PATH="$PATH:/root/.dotnet/tools" - dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider - dotnet codeartifact-creds install pre_build: commands: - dotnet nuget add source -n codeartifact $(aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format nuget --query repositoryEndpoint --output text)"v3/index.json" build: commands: - dotnet pack -o . - dotnet nuget push *.nupkg -s codeartifact

Windows

要使用dotnet以下方法发布 NuGet 软件包:

version: 0.2 phases: install: commands: - dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider - dotnet codeartifact-creds install pre_build: commands: - dotnet nuget add source -n codeartifact "$(aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format nuget --query repositoryEndpoint --output text)v3/index.json" build: commands: - dotnet pack -o . - dotnet nuget push *.nupkg -s codeartifact
隐私网站条款Cookie 首选项
© 2025, Amazon Web Services, Inc. 或其附属公司。保留所有权利。