.net-coregithub-actions.net-framework-version

Github actions fails for ASP.NET MVC project on .NET 4.6.1 that depends on .NET Standard 2 and .NET 8 projects


We have an ASP.NET MVC project running on .NET 4.6.1 that depends on 3 other projects.

Project 1 and 2 target both .NET Standard 2.0 and .NET 4.6.1.

<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>

Project 3 targets .NET 4.6.1 and .NET 8:

<TargetFrameworks>net461;net8.0</TargetFrameworks>

Now this was working before, but we updated Project 3 from .NET 6 to .NET 8 by editing the .csproj directly. No other changes were made. Project 3 is also used by 2 other .NET 8 applications (ASP.NET Core 8 MVC and Web API), so it works and builds in other github actions.

Here is our current .yaml file:

name: MVC Devel Builder
on:
  workflow_dispatch:
    inputs:
      branch_name:
        required: false
        description: The git branch name to build
        default: "master"
  push:
    branches:
      - master
    paths:
      - 'Project1/**'
      - 'Project2/**'
      - 'Project3/**'
      - 'mvc/**'
jobs:
  Build:
    runs-on: [self-hosted, windows-2019]
    steps:
    - name: Checkout
      uses: actions/checkout@v2
      with:
        ref: ${{ github.event.inputs.branch_name || 'master' }}
        submodules: 'true'
        
    - uses: Special internal nuget repo
      with:
        package-manager: nuget
    
    - name: Nuget restore
      run: nuget restore .\mvc\mvc.sln
    
    - name: Install msbuild
      uses: microsoft/setup-msbuild@v1
    
    - name: Run msbuild
      shell: cmd
      run: msbuild mvc/mvc.sln -p:Configuration=Staging
      
    - name: Setup VSTest Path
      uses: darenm/Setup-VSTest@v1.2
    
    - name: Run VSTest
      run: vstest.console.exe mvc/mvc.Tests/bin/Staging/mvc.tests.dll
    
    - name: Copy configs
      shell: cmd
      run: |-
        mkdir "mvc/transformed-config/"
        copy mvc\mvc\bin\mvc.dll.config mvc\transformed-config\Web.config
        
    - name: Archive artifacts
      uses: actions/upload-artifact@v3
      with:
        ...
          
    - name: Alert on failure
      if: ${{ failure() }}
      ...

I have been testing some things like setting up a new version of the dotnet sdk like:

- name: Setup .NET
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: '3.x'

and also just trying to limit the build scope to just net461 using this option on the msbuild command: -p:TargetFramework=net461 but that doesn't help either.

The errors I get are:

Error NETSDK1004: Assets file 'C:\image\actions-runner_work\auds\auds\project1\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.

When trying to specify the -p:TargetFramework:

Error NETSDK1045: The current .NET SDK does not support targeting .NET Standard 4.6.1. Either target .NET Standard 2.1 or lower, or use a version of the .NET SDK that supports .NET Standard 4.6.1.

Any help would be appreciated.

Thanks


Solution

  • I managed to get the action to work in a hacky way.

    The steps were to install the .net sdk using version 8.0.x, build the 3 problem projects using dotnet build and then remove them from the solution before running msbuild normally.

    Here is what the updated yaml file looks like:

    
    name: MVC Devel Builder
    on:
      workflow_dispatch:
        inputs:
          branch_name:
            required: false
            description: The git branch name to build
            default: "master"
      push:
        branches:
          - master
        paths:
          - 'Project1/**'
          - 'Project2/**'
          - 'Project3/**'
          - 'mvc/**'
    jobs:
      Build:
        runs-on: [self-hosted, windows-2019]
        steps:
        - name: Checkout
          uses: actions/checkout@v3
          with:
            ref: ${{ github.event.inputs.branch_name || 'master' }}
            submodules: 'true'
            
        - uses: Special internal nuget repo
          with:
            package-manager: nuget
        
        - name: Nuget restore
          run: nuget restore .\mvc\mvc.sln
        
        - name: Install msbuild
          uses: microsoft/setup-msbuild@v1.1
        
        - name: Setup .NET SDK
          uses: actions/setup-dotnet@v3
          with:
            dotnet-version: '8.0.x'  # Use a version that supports .NET Standard 2.0
        
        - name: Restore dependencies
          run: dotnet restore mvc/mvc.sln --configfile NuGet.Config
    
        - name: Build SDK-style projects
          run: dotnet build proj1/Project1.csproj --configuration Staging
    
        - name: Build SDK-style projects
          run: dotnet build proj2/Project2.csproj --configuration Staging
    
        - name: Build SDK-style projects
          run: dotnet build proj3/Project3.csproj --configuration Staging
    
        - name: Remove problematic projects from solution
          shell: pwsh
          run: |
            $solutionContent = Get-Content -Path mvc/mvc.sln -Raw
            $solutionContent = $solutionContent -replace '(?ms)Project\("{[^}]+}"\) = "Project1".*?EndProject\r?\n', ''
            $solutionContent = $solutionContent -replace '(?ms)Project\("{[^}]+}"\) = "Project2".*?EndProject\r?\n', ''
            $solutionContent = $solutionContent -replace '(?ms)Project\("{[^}]+}"\) = "Project3".*?EndProject\r?\n', ''
            $solutionContent | Set-Content -Path mvc/mvc.sln -Encoding UTF8
        
        - name: Run msbuild
          shell: cmd
          run: msbuild mvc/mvc.sln -p:Configuration=Staging
          
        - name: Setup VSTest Path
          uses: darenm/Setup-VSTest@v1.2
        
        - name: Run VSTest
          run: vstest.console.exe mvc/mvc.Tests/bin/Staging/mvc.tests.dll
        
        - name: Copy configs
          shell: cmd
          run: |-
            mkdir "mvc/transformed-config/"
            copy mvc\mvc\bin\mvc.dll.config mvc\transformed-config\Web.config
            
        - name: Archive artifacts
          uses: actions/upload-artifact@v3
          with:
            ...
              
        - name: Alert on failure
          if: ${{ failure() }}
          ...