Scenario
We have AWS account and .nupkg package (nuget fie) ready from dll, no matter how its been created either through VS/VS Code/Build Pipeline or any DevOps media. We want to setup a local Nuget repository in AWS which will used by team members. How will do that?
Workflow
- Create a repository in AWS CodeArtifact
- It create a domain and repository in CodeArtifacts
- Create a connection for repo that will use to connect through VS to add package reference.
- Push nuget package into repo.
Action
I am performing this action on my local win machine by using dot net cli and aws cli, we can inject same script anywhere in pipeline.
Create a file main.ps1
echo "set config"
aws configure set aws_access_key_id <aws_access_key_id>
aws configure set aws_secret_access_key <aws_secret_access_key>
aws configure set region "us-east-1" --profile default
echo "Verifying identity"
#aws sts get-caller-identity
aws cloudformation deploy --template-file formation.yml --stack-name codeartifacts-rnd
--parameter-overrides Key1=Value1 --tags type=rnd
aws codeartifact login --tool dotnet --repository compexfacker-upstream-repo
--domain rajkrs-get --domain-owner <YOUR ACCOUNT ID>
dotnet nuget push ".\ComplexFaker.1.0.7.nupkg"
-s https://rajkrs-get-<YOUR ACCOUNT ID>.d.codeartifact.us-east-1.amazonaws.com/nuget/compexfacker-upstream-repo/v3/index.json
--no-symbols true --skip-duplicate
Resources:
MyCodeArtifactDomain:
Type: 'AWS::CodeArtifact::Domain'
Properties:
DomainName: "rajkrs-get"
MyCodeArtifactUpstreamRepository:
Type: 'AWS::CodeArtifact::Repository'
Properties:
RepositoryName: "compexfacker-upstream-repo"
DomainName: !GetAtt MyCodeArtifactDomain.Name
ExternalConnections:
- public:nuget-org
MyCodeArtifactRepository:
Type: 'AWS::CodeArtifact::Repository'
Properties:
RepositoryName: "compexfacker-repo"
DomainName: !GetAtt MyCodeArtifactDomain.Name
Upstreams:
- !GetAtt MyCodeArtifactUpstreamRepository.Name
So what a we need to do is to run flowing command and it will pick default aws credential and will make a source entry in package manager tool
dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider
dotnet codeartifact-creds install
dotnet codeartifact-creds configure set profile default
dotnet nuget add source "https://rajkrs-get-<your account id>.d.codeartifact.us-east-1.amazonaws.com/nuget/compexfacker-upstream-repo/v3/index.json"
-n "rajkrs-get/compexfacker-upstream-repo"
Verify in VS options