# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
parameters:
- name: buildConfiguration # name of the parameter; required
  default: 'Release'
- name: projectFolder
  default: ' '

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

# - task: VSBuild@1
#   inputs:
#     solution: '$(solution)'
#     msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
#     platform: '$(buildPlatform)'
#     configuration: '$(buildConfiguration)'

# - task: VSTest@2
#   inputs:
#     platform: '$(buildPlatform)'
#     configuration: '$(buildConfiguration)'

# Restore packages
- task: DotNetCoreCLI@2
  displayName: Restore nuget packages
  inputs:
    command: restore
    projects: '*.csproj'
    workingDirectory: '${{ parameters.projectFolder}}'

# The first task is the dotnet command build, pointing to our csproj file
- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    command: 'build'
    arguments: '--configuration $(buildConfiguration)'
    projects: 'Kodestruct.Common/Kodestruct.Common.csproj'

- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    command: 'build'
    arguments: '--configuration $(buildConfiguration)'
    projects: 'Kodestruct.Common/Kodestruct.Common.csproj'
    

# The second task is dotnet pack command again pointing to the csproj file
# The nobuild means the project will not be compiled before running pack, because its already built in above step
- task: DotNetCoreCLI@2
  displayName: "dotnet pack"
  inputs:
    command: 'pack'
    arguments: '--configuration $(buildConfiguration)'
    packagesToPack: 'Kodestruct.Common/Kodestruct.Common.csproj'
    nobuild: true
    versioningScheme: 'off'

# The last task is a nuget command, nuget push
# This will push any .nupkg files to the 'TestFeed' artifact feed
# allowPackageConflicts allows us to build the same version and not throw an error when trying to push
# instead it just ingores the latest package unless the version changes
- task: NuGetCommand@2
  displayName: 'nuget push'
  inputs:
    command: 'push'
    feedsToUse: 'select'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'TestFeed'
    versioningScheme: 'off'
    allowPackageConflicts: true
Set up CI with Azure Pipelines
Set up CI with Azure Pipelines

[skip ci]