Wednesday, 30 March 2022

Setting up NuGet repository using Aws CodeArtifact


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?


  • 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.


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>
--no-symbols true --skip-duplicate

Create another file formation.yml
    Type: 'AWS::CodeArtifact::Domain'
      DomainName: "rajkrs-get"
    Type: 'AWS::CodeArtifact::Repository'
      RepositoryName: "compexfacker-upstream-repo"
      DomainName: !GetAtt MyCodeArtifactDomain.Name
        - public:nuget-org
    Type: 'AWS::CodeArtifact::Repository'
      RepositoryName: "compexfacker-repo"
      DomainName: !GetAtt MyCodeArtifactDomain.Name
        - !GetAtt MyCodeArtifactUpstreamRepository.Name

After running above main.ps1 in termina wi get that stack been created and package is pushed in to repository.

Now at steps is to browse on VS
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>"
-n "rajkrs-get/compexfacker-upstream-repo"

Verify in VS options