.netcontinuous-integrationgithub-actionsbuilding-github-actionsreact-native-windows

Github Action .NET Windows SDK error on build


I try to build a native .NET application with Github actions. After 2 days of trying and searching i will ask here.

The project is a solution with .NET 4.6.1 and React Native (both not updateable for legacy code reasons).

When i run the ci it always tell me this:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\Microsoft.Cpp.WindowsSDK.targets(46,5): error MSB8036: The Windows SDK version 10.0.18362.0 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution"

Here is my Github action code:

name: Build

on: [push]

jobs:
  build:
    name: "Build Termnial"

env:
  POWERSHELL_TELEMETRY_OPTOUT: 1
  DOTNET_CLI_TELEMETRY_OPTOUT: 1
  UseEnv: true

runs-on: windows-2019

steps:
  - uses: actions/checkout@v3

  - name: Setup Node.js
    uses: actions/setup-node@v3
    with:
      node-version: '16.x'

  - name: Setup MSBuild
    uses: microsoft/setup-msbuild@v1.3
    with:
      msbuild-architecture: x64

  - uses: actions/cache@v3
    with:
      path: ~/.nuget/packages
      # Look to see if there is a cache hit for the corresponding requirements file
      key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
      restore-keys: |
        ${{ runner.os }}-nuget

  - name: Build key file
    env:
      CERT_FILE: ${{ secrets.CERT_FILE }}
    shell: bash
    run: |
      echo "$CERT_FILE" > sideloading.base64
      certutil -decode sideloading.base64 SideloadingMaster.pfx

  - name: Install dependencies Node.js
    run: npm ci --legacy-peer-deps

  - uses: GuillaumeFalourd/setup-windows10-sdk-action@v1.11

  - name: Install Framework
    run: |
      choco install dotnet4.6.1
      choco install dotnet4.6.1-devpack
      

  - name: Build Terminal
  #  run: dotnet build --nologo --configuration Release -p:PackageCertificateKeyFile="SideloadingMaster.pfx" windows/project.sln
    run: msbuild .windows\project.sln /nologo -verbosity:minimal /p:Configuration=Release /p:Platform=x64 /p:AppxBundle=Never /bl /p:PackageCertificateKeyFile="SideloadingMaster.pfx" /p:RestorePackagesConfig=true /t:restore,build

I'm not sure what is wrong here and i'm not a .NET guy. So please help me someone.


Solution

  • I fixed it myself.

    It seems that the setup-node and the setup-msbuild actions where causing the problems. The windows runner comes with both preinstalled and the setup actions are messing with it. But you still have to install the correct windows sdk if it is not listed in the Gather environment info step

    Here is the working workflow file:

    name: Build
    
    on: [push]
    
    jobs:
      build:
        name: "Build Termnial"
    
        runs-on: windows-2019
    
        steps:
          - uses: actions/checkout@v3
    
          - name: Gather environment info
            run: npx envinfo
    
          - name: Decode pfx file
            run: |
              $PfxBytes = [System.Convert]::FromBase64String("${{ secrets.CERT_FILE }}")
              $PfxPath = [System.IO.Path]::GetFullPath("${{github.workspace}}\SideloadingMaster.pfx")
              Write-Host $PfxPath
              [System.IO.File]::WriteAllBytes("$PfxPath", $PfxBytes)
    
          - name: Install dependencies Node.js
            run: npm ci --legacy-peer-deps
     
          - uses: GuillaumeFalourd/setup-windows10-sdk-action@v1.11
            with:
              sdk-version: 18362
    
          - name: Build React Native
            run: npx react-native run-windows --no-packager --no-launch --arch x64 --release --verbose --logging --msbuildprops PackageCertificateKeyFile="SideloadingMaster.pfx"
    

    Got this information here microsoft/react-native-windows-samples within the .github folder.

    And thanks to VonC for trying to help me.