pipeline {
  agent any
  environment {
     APP_VERSION_PREFIX=sh(script: ' cat *.csproj| xmlstarlet sel -t -m "/Project/PropertyGroup/Version" -v . -n|awk -v def="1.0.0" "{print} END { if(NR==0) {print def} }"', returnStdout: true).trim()
     APP_NAME=sh(script: ' cat *.csproj| xmlstarlet sel -t -m "/Project/PropertyGroup/AssemblyName" -v . -n|awk -v def="App" "{print tolower(\\$0)} END { if(NR==0) {print def} }"', returnStdout: true).trim()
     APP_VERSION="${APP_VERSION_PREFIX}"
  }
  stages {
    stage('Dotnet Restore') {
      steps {
        sh '''dotnet restore CarbonLib.csproj'''
      }
    }
    stage('Dotnet Build') {
      steps {
        sh '''dotnet build CarbonLib.csproj'''
      }
    }
	stage('Dotnet Package') {
      steps {
        sh '''rm -rf nuget
              dotnet pack -c release -o nuget -p:PackageVersion=${APP_VERSION} CarbonLib.csproj'''
      }
    }
	stage('Dotnet Publish') {
      steps {
		sh '''dotnet nuget push nuget/*.nupkg -k 0c3e3afc-935b-3db1-b023-e0d4799e674d -s https://repository.akkerweb.nl/repository/nuget-hosted/'''
      }
    }
  }  
  post {
    always {
      emailext (
        body: '${DEFAULT_CONTENT}',
        mimeType: 'text/html',
        replyTo: '${DEFAULT_REPLYTO}',
        subject: '${DEFAULT_SUBJECT}',
        to: emailextrecipients([[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']])
      )
    }
  }
}