# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net

variables:

  - name: solution
    value: 'WPFSamples.sln'
  - name: msbuildonlysolution
    value: 'WPFSamples.msbuild.sln'
  - name: wpfgallerysolution
    value: './Sample Applications/WPFGallery/WPFGallery.sln'
  - name: LangVersion
    value: latest

trigger:
- release/*

pool:
  vmImage: 'windows-latest'

stages:
- stage: Build
  displayName: Build
  jobs:
  - job: Windows
    pool:
     vmImage: 'windows-latest'
    variables:
     - name: _Configuration
       value: Debug
     - name: _Platform
       value: x86
     - name: _ToolPlatform
       value: x86
     - name: _TargetFramework
       value: 'net10.0-windows'
    strategy:
     matrix:
      Debug-AnyCPU:
        _Configuration: Debug
        _Platform: 'Any CPU'
        _TargetFramework: 'net10.0-windows'
        _ToolPlatform: x86
      Debug-x64:
        _Configuration: Debug
        _Platform: 'x64'
        _TargetFramework: 'net10.0-windows'
        _ToolPlatform: x64
      Debug-x86:
        _Configuration: Debug
        _Platform: 'x86'
        _TargetFramework: 'net10.0-windows'
        _ToolPlatform: x86
      Release-AnyCPU:
        _Configuration: Release
        _Platform: 'Any CPU'
        _TargetFramework: 'net10.0-windows'
        _ToolPlatform: x86
      Release-x64:
        _Configuration: Release
        _Platform: 'x64'
        _TargetFramework: 'net10.0-windows'
        _ToolPlatform: x64
      Release-x86:
        _Configuration: Release
        _Platform: 'x86'
        _TargetFramework: 'net10.0-windows'
        _ToolPlatform: x86
    steps:
     - task: NuGetToolInstaller@1
       displayName: 'Download and Cache Nuget tool'

     - powershell: ./eng/EnsureGlobalJsonSdk.ps1 -g global.json -i "$(Agent.ToolsDirectory)/dotnet" -a $(_ToolPlatform) -f $(_TargetFramework) -Verbose
       displayName: Install .NET Core 

     - powershell: |
          Write-Host "Path Environment Variable:"
          Write-Host $env:PATH
          Write-Host 
          Write-Host "List of Installed .NET Core SDK's"
          dotnet --list-sdks
       displayName: List .NET SDK's

     - task: NuGetCommand@2
       displayName: 'Restore .NET Core Samples Using NuGet'
       inputs:
        restoreSolution: '$(solution)'
     
     - task: NuGetCommand@2
       displayName: 'Restore MSBuild-only .NET Core Samples Using NuGet'
       inputs:
        restoreSolution: '$(msbuildonlysolution)'

     - task: NuGetCommand@2
       displayName: 'Restore WPF Gallery Using NuGet'
       inputs:
        restoreSolution: '$(wpfgallerysolution)'

     - task: VSBuild@1
       continueOnError: true
       displayName: 'Build .NET Core Samples using VSBuild'
       inputs:
        vsVersion: latest
        solution: '$(solution)'
        platform: '$(_Platform)'
        msbuildArchitecture: '$(_ToolPlatform)'
        configuration: '$(_Configuration)'
        msbuildArgs: /m /bl:"$(Build.ArtifactStagingDirectory)\vsbuild\vsbuild.$(_Configuration).$(_Platform).$(_TargetFramework).binlog" /p:LangVersion=$(LangVersion)

     - task: VSBuild@1
       continueOnError: true
       displayName: 'Build MSBuild-only.NET Core Samples using VSBuild'
       inputs:
        vsVersion: latest
        solution: '$(msbuildonlysolution)'
        platform: '$(_Platform)'
        msbuildArchitecture: '$(_ToolPlatform)'
        configuration: '$(_Configuration)'
        msbuildArgs: /m /bl:"$(Build.ArtifactStagingDirectory)\vsbuild\msbuild.vsbuild.$(_Configuration).$(_Platform).$(_TargetFramework).binlog" /p:LangVersion=$(LangVersion)

     - task: VSBuild@1
       continueOnError: true
       displayName: 'Build WPF Gallery using VSBuild'
       inputs:
        vsVersion: latest
        solution: '$(wpfgallerysolution)'
        platform: '$(_Platform)'
        msbuildArchitecture: '$(_ToolPlatform)'
        configuration: '$(_Configuration)'
        msbuildArgs: /m /bl:"$(Build.ArtifactStagingDirectory)\vsbuild\wpfgallery.vsbuild.$(_Configuration).$(_Platform).$(_TargetFramework).binlog" /p:LangVersion=$(LangVersion)
       condition: ne(variables['_Platform'], 'x86')
       
     - task: PublishBuildArtifacts@1
       continueOnError: true
       displayName: 'Publish .NET Core VSBuild Build Logs'
       inputs:
        PathtoPublish: $(Build.ArtifactStagingDirectory)\vsbuild
        ArtifactName: 'Build Logs'
        publishLocation: 'Container'

     - task: PowerShell@2
       displayName: 'Clean Files From Previous Build'
       inputs:
        targetType: 'inline'
        script: |
          # Write your PowerShell commands here.
          
          git clean -xdf

     - task: DotNetCoreCLI@2
       continueOnError: true
       displayName: 'Restore .NET Core Samples using dotnet.exe'
       inputs:
        command: 'restore'
        configuration: $(_Configuration)
        projects: '$(solution)'
        feedsToUse: 'config'
        nugetConfigPath: 'NuGet.config'

     - task: DotNetCoreCLI@2
       continueOnError: true
       displayName: 'Restore WPF Gallery using dotnet.exe'
       inputs:
        command: 'restore'
        configuration: $(_Configuration)
        projects: '$(wpfgallerysolution)'
        feedsToUse: 'config'
        nugetConfigPath: 'NuGet.config'

     - task: DotNetCoreCLI@2
       continueOnError: true
       displayName: 'Build .NET Core Samples using dotnet.exe'
       inputs:
        command: 'build'
        projects: '$(solution)'
        configuration: $(_Configuration)
        arguments: '/bl:"$(Build.ArtifactStagingDirectory)\netcore\dotnet.$(_Configuration).$(_Platform).$(_TargetFramework).binlog" /p:Platform="$(_Platform)" /p:LangVersion=$(LangVersion)'

     - task: DotNetCoreCLI@2
       continueOnError: true
       displayName: 'Build WPF Gallery using dotnet.exe'
       inputs:
        command: 'build'
        projects: '$(wpfgallerysolution)'
        configuration: $(_Configuration)
        arguments: '/bl:"$(Build.ArtifactStagingDirectory)\netcore\dotnet.$(_Configuration).$(_Platform).$(_TargetFramework).binlog" /p:Platform="$(_Platform)" /p:LangVersion=$(LangVersion)'
       condition: ne(variables['_Platform'], 'x86')

     - task: PublishBuildArtifacts@1
       displayName: 'Publish .NET Core Dotnet.exe Build Logs'
       inputs:
        PathtoPublish: $(Build.ArtifactStagingDirectory)\netcore
        ArtifactName: 'Build Logs'
        publishLocation: 'Container'
    
     - task: ComponentGovernanceComponentDetection@0
       displayName: "Component Detection"

     - task: PowerShell@2
       displayName: 'Clean Files From Previous Builds'
       inputs:
        targetType: 'inline'
        script: |
          # Write your PowerShell commands here.
          
          git checkout global.json
          git clean -xdf        
