Build .NET framework and .NET Core projects with Jenkins

This pipeline will run only on windows containers because .NET Framework images are supported only on Windows.
NB: tough the .NET Core code works fine on Linux system, I need to keep all build artifacts together to have a single “deploy package”, so windows environment is preferred.

pipeline {
    agent {
        docker { 
      
          image 'mcr.microsoft.com/dotnet/framework/sdk:4.8'
          label 'windows'
        }
        
    }
    stages {
         stage('Restore nuget') {
            steps {
              
              
                bat 'dotnet restore' //for .NET core
                bat 'nuget restore BigProject.sln' // for .NET framework
               
            }
        }
        stage('Build') {
            steps {
               
                bat 'dotnet build --configuration Release ./BigProject.NetCoreApp/BigProject.NetCoreApp.csproj'           
                bat 'msbuild BigProject.sln /target:BigProject_NetFrameworkApp /p:Configuration=Release'
               
            }
        }
        stage('Test') {
            steps {
                bat 'dotnet test --logger trx ./BigProject.NetCoreApp.Test/BigProject.NetCoreApp.Test.csproj'
            }
             post {
                    always {
                      //plugin: https://plugins.jenkins.io/mstest/
                        mstest testResultsFile:"**/*.trx", keepLongStdio: true
                    }
        
                }           
        }
        
        stage('Deploy') {
            steps {
                bat 'mkdir deploy'
                bat 'dotnet publish --self-contained --runtime win-x64 -c Release ./BigProject.NetCore/BigProject.NetCore.csproj -o ./deploy/BigProject.NetCore'            
           	    //NOT BE TESTED YET
                bat 'msbuild BigProject.sln /target:BigProject_NetFrameworkApp /p:Configuration=Release /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl=./deploy/BigProject.NetFrameworkApp'
                archiveArtifacts artifacts: 'deploy/**', fingerprint: true
                
            }
        }
    }
}

Considerations

Two syntax for same logic

It is necessary because the dotnet command line does not work well with net framework projects, this approach assures more stability

No real “publish” command for .NET Framework

It’s just a change of the output-dir.
At the moment I’m not sure if it supports XML transform because it is managed by Web Deploy

Work in progress

I will keep this post update with future improvements