Thursday, January 19, 2023

Submit .Net class library to Azure Artifacts Feed

 Azure Artifacts feed provides great means to share the common reusable components across your organization. In the following code base I will display a template for Azure DevOps build pipeline. 

trigger:
- 'main'

pool:
vmImage: ubuntu-latest
demands:
- npm

variables:
buildConfiguration: 'Release'
dotNetFramework: 'net7.0'
targetRuntime: 'linux-x64'
moduleName: 'ModuleName'
entityTypeName: 'EntityType'
// Once you create a feed, that ID will be added here.
vstsFeedId: '<A Guid>'
major: '1'
minor: '0'
revision: $[counter(variables['minor'], 1)]
nugetVersion: '$(major).$(minor).$(revision)'

steps:
- task: NuGetAuthenticate@1
inputs:
forceReinstallCredentialProvider: true

// Optional: Run unit tests
- task: DotNetCoreCLI@2
displayName: 'Run unit tests - $(buildConfiguration)'
inputs:
command: 'test'
arguments: '--framework $(dotNetFramework) --configuration $(buildConfiguration)'
publishTestResults: true
projects: '**/*.Tests.csproj'

// Does packaging. Nuget version is automatically increased to next revision.
- task: NuGetCommand@2
displayName: 'Nuget Pack'
inputs:
command: 'pack'
packagesToPack: '**/$(moduleName).$(entityTypeName).csproj'
versionEnvVar: 'nugetVersion'
versioningScheme: 'byEnvVar'
packDestination: '$(Build.ArtifactStagingDirectory)'

- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
publishLocation: 'pipeline'

- task: NuGetCommand@2
displayName: 'Nuget Push'
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: '$(vstsFeedId)'

No comments:

Post a Comment