trigger:
    - master
pool:
    vmImage: 'VS2017-Win2016'
variables:
    PROJECT_NAME:     'Cube.Xui'
    PROJECT_PLATFORM: 'Any CPU'
    PROJECT_CONFIG:   'Release'
    PROJECT_BIN:      'bin\$(PROJECT_PLATFORM)\$(PROJECT_CONFIG)\net45'
    PROJECT_PACKAGE:  '..\packages'
    TEST_TOOL:        '$(PROJECT_PACKAGE)\OpenCover\4.7.922\tools\OpenCover.Console.exe'
    TEST_CORETOOL:    '$(PROJECT_PACKAGE)\NUnit.ConsoleRunner\3.10.0\tools\nunit3-console.exe'
    TEST_FILTERS:     '+[Cube*]* -[*]*NativeMethods -[*]*Properties.*'
    TEST_RESULT:      'TestResult.xml'
    TEST_COVERAGE:    'CoverResults.xml'
    TEST_LOG:         '$(Build.ArtifactStagingDirectory)\TestResults'

steps:
- task: NuGetToolInstaller@0
  inputs:
    versionSpec: '>= 4.9'
  displayName: 'Use NuGet 4.9 or later'

- script: |
    nuget restore "$(PROJECT_NAME).sln"
  displayName: 'Restore NuGet packages'

- task: VSBuild@1
  inputs:
    solution: '$(PROJECT_NAME).sln'
    platform: '$(PROJECT_PLATFORM)'
    configuration: '$(PROJECT_CONFIG)'
  displayName: 'Build solution'

- script: >
    "$(TEST_TOOL)"
    -log:Error
    -register:user
    -target:"$(TEST_CORETOOL)"
    -targetargs:"$(PROJECT_NAME).Tests.dll"
    -targetdir:"Tests\$(PROJECT_BIN)"
    -returntargetcode
    -hideskipped:All
    -output:"$(TEST_COVERAGE)"
    -filter:"$(TEST_FILTERS)"
  displayName: 'Run tests via OpenCover and NUnit'

- script: |
    pip install codecov
    codecov -f "$(TEST_COVERAGE)" -t $(CODECOV_TOKEN)
  displayName: 'Send coverage results to Codecov'

- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'NUnit'
    testResultsFiles: '**\$(TEST_RESULT)'
  displayName: 'Publish test results'

- task: NuGetCommand@2
  inputs:
    command: 'pack'
    packagesToPack: 'Libraries\$(PROJECT_NAME).csproj'
    configuration: '$(PROJECT_CONFIG)'
  displayName: 'Create NuGet package'

- task: CopyFiles@2
  inputs:
    contents: '**\*.log'
    targetFolder: '$(TEST_LOG)'
    overWrite: true
  displayName: 'Copy log files'

- task: CopyFiles@2
  inputs:
    contents: '**\$(TEST_RESULT)'
    targetFolder: '$(TEST_LOG)'
    overWrite: true
  displayName: 'Copy test results'

- task: CopyFiles@2
  inputs:
    contents: '$(TEST_COVERAGE)'
    targetFolder: '$(TEST_LOG)'
    overWrite: true
  displayName: 'Copy coverage results'

- task: PublishPipelineArtifact@0
  inputs:
    artifactName: '$(PROJECT_NAME)'
    targetPath: '$(Build.ArtifactStagingDirectory)'
  displayName: 'Publish pipline artifacts'

Set up CI with Azure Pipelines
Set up CI with Azure Pipelines