Skip to content

Instantly share code, notes, and snippets.

@Gimly
Last active March 21, 2024 14:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gimly/054f3a1d1c14342d71eef639b305e922 to your computer and use it in GitHub Desktop.
Save Gimly/054f3a1d1c14342d71eef639b305e922 to your computer and use it in GitHub Desktop.
A sample azure pipeline that creates a nuget package and publish it to Azure DevOps artifacts
trigger:
- master
pool: 'Hosted Windows 2019 with VS2019'
variables:
buildConfiguration: 'Release'
stages:
- stage: build_pack
displayName: 'Build and pack project'
jobs:
- job: build
displayName: 'Build project'
steps:
- template: build_steps.yml
- stage: deploy_to_nuget
displayName: 'Deploy to NuGet'
dependsOn: build_pack
condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/master'))
jobs:
- deployment: nuget_deploy
displayName: Deploy to Nuget
environment: Private Nuget
strategy:
runOnce:
deploy:
steps:
- task: NuGetCommand@2
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/**/*.nupkg;!$(Pipeline.Workspace)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'your feed GUID'
steps:
- checkout: self
clean: true
lfs: true
- task: GitVersion@5
inputs:
runtime: 'core'
configFilePath: 'GitVersion.yml'
- task: Assembly-Info-NetCore@2
displayName: 'Set Assembly Info'
inputs:
Path: "$(Build.SourcesDirectory)"
FileNames: '**/*.csproj'
InsertAttributes: true
FileEncoding: "auto"
WriteBOM: false
Product: 'My great product'
Company: 'My great company'
Copyright: 'Copyright My great company $(date:YYYY)'
LogLevel: "verbose"
FailOnWarning: false
VersionNumber: '$(GitVersion.AssemblySemVer)'
FileVersionNumber: '$(GitVersion.AssemblySemVer)'
InformationalVersion: '$(GitVersion.InformationalVersion)'
- task: DotNetCoreCLI@2
displayName: 'NuGet Restore'
inputs:
command: restore
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: Build all projects
inputs:
projects: '**/*.csproj'
arguments: '-p:Version=$(GitVersion.AssemblySemVer) --configuration $(buildConfiguration) --no-restore'
- task: CopyFiles@2
displayName: 'Copy bin files'
inputs:
sourceFolder: 'src\MyGreatProject\bin\$(BuildConfiguration)\netstandard2.0'
targetFolder: '$(Build.ArtifactStagingDirectory)\Binaries'
- task: DotNetCoreCLI@2
displayName: Pack Nuget
inputs:
command: pack
packagesToPack: 'src\MyGreatProject\MyGreatProject.csproj'
packDirectory: '$(Build.ArtifactStagingDirectory)\Nuget'
nobuild: true
includesymbols: true
includesource: true
versioningScheme: byEnvVar
versionEnvVar: GitVersion.NuGetVersionV2
- task: PublishBuildArtifacts@1
displayName: 'Publish the nuget packages'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)\Nuget'
ArtifactName: 'MyGreatProject'
publishLocation: 'Container'
- task: PublishBuildArtifacts@1
displayName: 'Publish the binaries'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)\Binaries'
ArtifactName: 'MyGreatProjectBinaries'
publishLocation: 'Container'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment