GitHub Action with .NET Framework 4

1.1k views Asked by At

Is it possible to create a GitHub Action for building an old .NET 4 based app?

I've created such pipeline:

name: EZRep Build

on:
  push:
    branches: master

jobs:
  build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2
    
    - name: Setup MSBuild
      uses: microsoft/setup-msbuild@v1

    - uses: nuget/setup-nuget@v1
      with:
        nuget-api-key: ${{ secrets.NuGetAPIKey }}
        nuget-version: '5.x'
      
    - name: Navigate to Workspace
      run: cd $GITHUB_WORKSPACE

    - name: Create Build Directory
      run: mkdir _build


    - name: Restore Packages
      run: nuget restore MazeBallWeb/MazeBall.sln

    - name: Build Solution
      run: |
        msbuild.exe MazeBallWeb/MazeBall.sln /nologo /nr:false /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:platform="Any CPU" /p:configuration="Release" /p:PublishUrl="../_build"
        

But the last step fails with en error:

error MSB3644: The reference assemblies for .NETFramework,Version=v4.6.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpack...

Is it possible to configure .NET 4 SDK on the Windows runner? I need old .NET 4, not .NET Core.

2

There are 2 answers

0
szymmirr On

windows-latest doesn't support anything older than .NET Framework 4.5.2. You can use windows-2019 instead, which goes as far back as .NET Framework 4.0.

Here you can see exact packages installed: windows-2019 and windows-2022 (search for Microsoft.Net.Component)

3
Shane Ward On

A durable solution is to use https://github.com/actions/setup-dotnet, which should work on all windows runners.