Nuget Cheatsheet

List alle cacher

dotnet nuget locals all --list

Slett cache

dotnet nuget locals all --clear

Azure pipeline for å pushe beta versjoner

trigger:
  branches:
    include:
      - '*'
    exclude:
      - master
pool:
  vmImage: 'windows-latest'
variables:
  buildConfiguration: 'Release'
  
steps:
- powershell: |
    $xml = [Xml] (Get-Content .\MyProject.csproj)
    $version = $xml.Project.PropertyGroup.Version
    $versions = $version.Split(".")
    $major = $versions[0]
    $minor= $versions[1]
    $patch= $versions[2]
    
    $today = $(Get-Date -Format yyyyMMdd)
    
    $sanitizedSourceBranch = $env:BUILD_SOURCE_BRANCH.replace("refs/heads/", "").replace("/", "--")
    $fullVersion="${major}.${minor}.${patch}-${today}-${sanitizedSourceBranch}-$env:BUILD_BUILD_ID" 
    
    # This (insane) syntax makes the variable available to the rest of the pipeline: 
    Write-Host "##vso[task.setvariable variable=FullVersionNumber]$fullVersion"
  env:
    BUILD_SOURCE_BRANCH: $(Build.SourceBranch)
    BUILD_BUILD_ID: $(Build.BuildId)
  displayName: 'Generate nuget version number'
- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'select'
    vstsFeed: '{myFeedId}'
- task: VSBuild@1
  displayName: 'vs build'
  inputs:
    solution: '**\*.sln'
    configuration: 'release'
- task: DotNetCoreCLI@2
  displayName: 'Nuget pack'
  inputs:
    command: pack
    packagesToPack: '**/MyProject.csproj'
    versioningScheme: 'byEnvVar'
    versionEnvVar: 'FullVersionNumber'
- task: NuGetCommand@2
  displayName: 'nuget push'
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: '{myFeedId}'