本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在 CodeBuild 中使用 NuGet 套件
下列步驟已使用 CodeBuild 所提供 Docker 映像中列出的作業系統進行測試。
使用 IAM 角色設定許可
在 CodeBuild 中使用 CodeArtifact 中的 NuGet 套件時,需要這些步驟。 CodeBuild
登入 AWS 管理主控台 並開啟位於 https://https://console.aws.amazon.com/iam/
的 IAM 主控台。 -
在導覽窗格中,選擇角色。在角色頁面上,編輯 CodeBuild 組建專案所使用的角色。此角色必須具有下列許可。
重要
如果您也想要使用 CodeBuild 發佈套件,請新增
codeartifact:PublishPackageVersion許可。如需詳細資訊,請參閱《IAM 使用者指南》中的修改角色。
使用 NuGet 套件
若要從 CodeBuild 使用 NuGet 套件,請在專案的 buildspec.yaml 檔案中包含下列項目。
在
install區段中,安裝 CodeArtifact Credential Provider 來設定命令列工具,例如msbuild和dotnet,以建置套件並將其發佈至 CodeArtifact。在
pre-build區段中,將 CodeArtifact 儲存庫新增至 NuGet 組態。
請參閱下列buildspec.yaml範例。如需詳細資訊,請參閱搭配 NuGet 使用 CodeArtifact 。
安裝登入資料提供者並新增儲存庫來源後,您可以從 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 --domainmy_domain--domain-owner111122223333--repositorymy_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 --domainmy_domain--domain-owner111122223333--repositorymy_repo--format nuget --query repositoryEndpoint --output text)v3/index.json" build: commands: - dotnet add package <packageName> --source codeartifact
使用 NuGet 套件建置
若要從 CodeBuild 使用 NuGet 套件建置 ,請在專案的 buildspec.yaml 檔案中包含下列項目。
在
install區段中,安裝 CodeArtifact Credential Provider 來設定命令列工具,例如msbuild和dotnet,以建置套件並將其發佈至 CodeArtifact。在
pre-build區段中,將 CodeArtifact 儲存庫新增至 NuGet 組態。
請參閱下列buildspec.yaml範例。如需詳細資訊,請參閱搭配 NuGet 使用 CodeArtifact 。
安裝登入資料提供者並新增儲存庫來源後,您可以從 dotnet build build區段執行 NuGet CLI 工具命令,例如 。
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 build
若要使用 建置 NuGet 套件msbuild:
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 --domainmy_domain--domain-owner111122223333--repositorymy_repo--format nuget --query repositoryEndpoint --output text)"v3/index.json" build: commands: - msbuild -t:Rebuild -p:Configuration=Release
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 --domainmy_domain--domain-owner111122223333--repositorymy_repo--format nuget --query repositoryEndpoint --output text)v3/index.json" build: commands: - dotnet build
若要使用 建置 NuGet 套件msbuild:
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 --domainmy_domain--domain-owner111122223333--repositorymy_repo--format nuget --query repositoryEndpoint --output text)v3/index.json" build: commands: - msbuild -t:Rebuild -p:Configuration=Release
發佈 NuGet 套件
若要從 CodeBuild 發佈 NuGet 套件,請在專案的 buildspec.yaml 檔案中包含下列項目。
在
install區段中,安裝 CodeArtifact Credential Provider 來設定命令列工具,例如msbuild和dotnet,以建置套件並將其發佈至 CodeArtifact。在
pre-build區段中,將 CodeArtifact 儲存庫新增至 NuGet 組態。
請參閱下列buildspec.yaml範例。如需詳細資訊,請參閱搭配 NuGet 使用 CodeArtifact 。
安裝登入資料提供者並新增儲存庫來源後,您可以從 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 --domainmy_domain--domain-owner111122223333--repositorymy_repo--format nuget --query repositoryEndpoint --output text)"v3/index.json" build: commands: - dotnet pack -o . - dotnet nuget push *.nupkg -s 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 --domainmy_domain--domain-owner111122223333--repositorymy_repo--format nuget --query repositoryEndpoint --output text)v3/index.json" build: commands: - dotnet pack -o . - dotnet nuget push *.nupkg -s codeartifact