microsoft / github-actions-for-desktop-apps

This repo contains a sample WPF application to demonstrate how to create CI/CD pipelines using GitHub Actions.
MIT License
353 stars 109 forks source link

Unable to fix error on CI workflow #38

Closed CiucurDaniel closed 3 years ago

CiucurDaniel commented 3 years ago

I am trying to set-up the CI workflow for an app that I develop with a friend, but I simply cannot pass the "Restore the application" step, I keep getting the following error.

_Run msbuild $env:Solution_Path /t:Restore /p:Configuration=$env:Configuration Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET Framework Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file. Error: Process completed with exit code 1._

I made a test repo where I tried again to set up but I get the same error. The test repo is: https://github.com/CiucurDaniel/TestCorectAppWithCI

error_log file_structure

LanceMcCarthy commented 3 years ago

You do not have a Solution_Path variable defined in your ENV section

image

UPDATE I have forked your repo, update the workflow and opened this Pull Request https://github.com/CiucurDaniel/TestCorectAppWithCI/pull/1

LanceMcCarthy commented 3 years ago

If you would like to see real world workflows that do a CI workflow and two CD workflows. Visit https://github.com/LanceMcCarthy/MediaFileManager/tree/main/.github/workflows

I show you the following

ci_main.yml a simple, clean CI builds. These are quick debug builds to validate nothing is breaking

cd_release_sideload.yml A build that packages and code-signs a side-loadable version of the application. I also show you how you can upload the appinstaller package to your ow cool-looking store website

cd_release_msstore.yml This builds the project for Microsoft Store. In this case you do not sign the code because Microsoft does that for you. what is most important here is that you've updated the manifest to use your MS Store publisher info,

You can achieve similar with a Matrix, but keep in mind that a Matrix is better suited for different build on the same branch, while a separate workflow is better for different branches that have their own responsibilities. (For example ci.yaml and cd.yaml).

CiucurDaniel commented 3 years ago

Hi! First of all wow, thanks for the quick and efficient response!

I did add your CI file to my real project repository: https://github.com/CiucurDaniel/Budget-Planner/blob/master/.github/workflows/continuous-integration.yml

Example from last failed build: https://github.com/CiucurDaniel/Budget-Planner/runs/2034363562?check_suite_focus=true

However, I still get some errors (listed below): searched a little bit for those but I really do not know how to fix them

"D:\a\Budget-Planner\Budget-Planner\BudgetPlanner.sln" (Restore target) (1) -> (Restore target) -> D:\a\Budget-Planner\Budget-Planner\BudgetPlannerWAP\BudgetPlannerWAP.wapproj : error NU1102: Unable to find package Microsoft.Windows.SDK.BuildTools with version (>= 10.0.19041.8) [D:\a\Budget-Planner\Budget-Planner\BudgetPlanner.sln] D:\a\Budget-Planner\Budget-Planner\BudgetPlannerWAP\BudgetPlannerWAP.wapproj : error NU1102: - Found 2 version(s) in nuget.org [ Nearest version: 10.0.19041.1 ] [D:\a\Budget-Planner\Budget-Planner\BudgetPlanner.sln] D:\a\Budget-Planner\Budget-Planner\BudgetPlannerWAP\BudgetPlannerWAP.wapproj : error NU1102: - Found 0 version(s) in Microsoft Visual Studio Offline Packages [D:\a\Budget-Planner\Budget-Planner\BudgetPlanner.sln]

0 Warning(s) 1 Error(s)

Time Elapsed 00:00:20.10 Error: Process completed with exit code 1.

LanceMcCarthy commented 3 years ago

Looking at your error message, it is looking for a weird SDK version number 19041.8 I'm not familiar with (it is usually a 0 or a 1 on the end, I've never seen a hardcoded 8)

Do you have a mispelling in

I'm not going to be of much assistance with prices setup of your DevOps requirement, but I can point you in the right direction.

First, I would not use .NET Core 3.1 for the WPF project. That's sooo 3 years ago 😎. Instead, upgrade it to .NET 5.

To do that just open your WPF project's csproj file and change it to the following:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
        <UseWPF>true</UseWPF>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.1.3" />
        <PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.19041.1" />
    </ItemGroup>

    <ItemGroup>
        <None Update="Properties\Settings.settings">
            <Generator>PublicSettingsSingleFileGenerator</Generator>
            <LastGenOutput>Settings.Designer.cs</LastGenOutput>
        </None>
    </ItemGroup>
</Project>

After that change, and you confirmed it is working locally, you can update your workflow's .NET Core and MSBuild steps to

    # Install the .NET Core workload
    - name: Install .NET Core
      uses: actions/setup-dotnet@v1.7.2
      with:
        dotnet-version: '5.0.x'

    - name: Setup MSBuild.exe
      uses: microsoft/setup-msbuild@v1.0.2
      with:
        vs-version: '[16.8,16.9)'

Notice the .NET version and the MSBuld versions.

If you continue to have trouble, please take a closer look at my repo's workflow and project configuration . It is a confirmed working and distributed project. https://github.com/LanceMcCarthy/MediaFileManager

LanceMcCarthy commented 3 years ago

Hi @CiucurDaniel,

I'm closing this thread as 'unrelated', because the problem you're having is unrelated to a issue with the demo's code or workflow YAML itself.

That said, I want to be able to help you if you're still having trouble. Feel free to DM me on Twitter and we can chat about how I can assist further https://twitter.com/lancewmccarthy.

CiucurDaniel commented 3 years ago

Hi there, I'm leaving here this veery basic workflow maybe it will help some beginners. I still didn't manage to fix the other one (guess I need more documentation on actions and also on WPF packaging) but I managed to do this one.

The repository: https://github.com/CiucurDaniel/BudgetPlannerWPF (those who use it make sure to change: dotnet restore [Your path to the .csproj here] )

# Worlflow used to build the application on every push to the master branch to assure a Continuous Integration

name: .NET CI workflow

on:
  push:
    branches: [ master ]

jobs:
  build:

    runs-on: windows-latest

    env:
      ACTIONS_ALLOW_UNSECURE_COMMANDS: true

    steps:
    - uses: actions/checkout@v2

    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x

    - name: Setup Nuget.exe
      uses: warrenbuckley/Setup-Nuget@v1

    - name: Nuget Restore 
      run: nuget restore

    - name: Restore dependencies
      run: dotnet restore ./BudgetPlanner/BudgetPlanner.csproj
    - name: Build
      run: dotnet build --no-restore

    # Currently there are no tests in the project if you have test un-comment this
    #- name: Test
    # run: dotnet test --no-build --verbosity normal
LanceMcCarthy commented 3 years ago

Thanks for sharing Daniel.

FYI

The ACTIONS_ALLOW_UNSECURE_COMMANDS setting is only to allow an environment variable to be set at the global level (i.e. so they work form job to job). Since I do not see any env variables set at the global level, you don't need it, so I'd recommend removing it as a better default security stance. For more information about why allowing global variable sis a security risk, see https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

If any of your custom actions fails with it disabled, open an Issue in their repo (it is because they use set-env or add-path command)