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
352 stars 109 forks source link

YML file to build WPF application targeted to .NET core 3.1 #46

Closed PramodKumarHK89 closed 2 years ago

PramodKumarHK89 commented 2 years ago

I’ve a WPF application targeted to .NET core 3.1 and I’m trying to build and publish it with below YML file in GitHub Action

https://github.com/PramodKumarHK89/MicrosoftIdentityPlatformEditor/blob/5d882caa5c220c846645ddcde0d0252ea6e9a01a/.github/workflows/dotnet-desktop.yml

However, build fails with below errors.

Warning: C:\Users\runneradmin\AppData\Local\Microsoft\dotnet\sdk\3.1.417\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(349,5): warning NETSDK1107: Microsoft.NET.Sdk.WindowsDesktop is required to build Windows desktop applications. 'UseWpf' and 'UseWindowsForms' are not supported by the current SDK. [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 14CSC : warning CS8032: An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Users\runneradmin.nuget\packages\system.text.json\6.0.2\analyzers\dotnet\roslyn3.11\cs\System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.. [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 15CSC : warning CS8032: An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Users\runneradmin.nuget\packages\system.text.json\6.0.2\analyzers\dotnet\roslyn4.0\cs\System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.. [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 16Error: AssemblyInfo.cs(3,12): error CS0246: The type or namespace name 'ThemeInfoAttribute' could not be found (are you missing a using directive or an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 17Error: AssemblyInfo.cs(3,12): error CS0246: The type or namespace name 'ThemeInfo' could not be found (are you missing a using directive or an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 18Error: AssemblyInfo.cs(4,5): error CS0103: The name 'ResourceDictionaryLocation' does not exist in the current context [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 19Error: AssemblyInfo.cs(7,5): error CS0103: The name 'ResourceDictionaryLocation' does not exist in the current context [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 20Error: MainWindow.xaml.cs(7,22): error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 21Error: MainWindow.xaml.cs(8,22): error CS0234: The type or namespace name 'Data' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 22Error: MainWindow.xaml.cs(9,22): error CS0234: The type or namespace name 'Documents' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 23Error: MainWindow.xaml.cs(11,22): error CS0234: The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 24Error: MainWindow.xaml.cs(12,22): error CS0234: The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 25Error: MainWindow.xaml.cs(13,22): error CS0234: The type or namespace name 'Navigation' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 26Error: MainWindow.xaml.cs(14,22): error CS0234: The type or namespace name 'Shapes' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 27Error: MainWindow.xaml.cs(18,22): error CS0234: The type or namespace name 'Interop' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 28Error: MainWindow.xaml.cs(29,39): error CS0246: The type or namespace name 'Window' could not be found (are you missing a using directive or an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 29Error: App.xaml.cs(16,32): error CS0246: The type or namespace name 'Application' could not be found (are you missing a using directive or an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 30Error: MainWindow.xaml.cs(43,56): error CS0246: The type or namespace name 'RoutedEventArgs' could not be found (are you missing a using directive or an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj] 31Error: MainWindow.xaml.cs(126,58): error CS0246: The type or namespace name 'RoutedEventArgs' could not be found (are you missing a using directive or an assembly reference?) [D:\a\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor\MicrosoftIdentityPlatformEditor.csproj]

I’m not sure whats wrong with the YML. When I build it locally with VS 2022, build succeeds. Does anyone has a YAML file which I can use it in the GitHub Action to build WPF application targeted to .NET core 3.1

Here is my project https://github.com/PramodKumarHK89/MicrosoftIdentityPlatformEditor/tree/5d882caa5c220c846645ddcde0d0252ea6e9a01a

LanceMcCarthy commented 2 years ago

Hi Pramod,

Open the csproj file and look at Line 1. This is what the error is complaining about.

If you add .WindowsDesktop after the .Sdk, it will clear that error.

The reason is because in netcore31 you had to define it there. In net5 and later, this is no longer necessary.

LanceMcCarthy commented 2 years ago

I ultimately recommend not compiling with the 3.1 SDK. Leave the csproj as it is, but install .net6 instead.

I will clone your repo today and take a closer look, then open a PR with the changes

PramodKumarHK89 commented 2 years ago

Thanks @LanceMcCarthy. That worked for me.

Additionally, can you help me with editing the yml file so that, after the build, I want the exe to be present in the release folder (beside tags)

LanceMcCarthy commented 2 years ago

Thanks @LanceMcCarthy. That worked for me.

Additionally, can you help me with editing the yml file so that, after the build, I want the exe to be present in the release folder (beside tags)

Sure thing, give me an hour or so (im on the east cost US, not at a PC yet)

PramodKumarHK89 commented 2 years ago

@LanceMcCarthy I'm using one of the NUGET packages(Microsoft.Identity.Client.Desktop) which doesn't compile in .NET 6

LanceMcCarthy commented 2 years ago

@PramodKumarHK89 I had a chance to review your project and workflow more closely. Since this is purely a WPF project without a MSIX packaging project, it is a different approach than what this repository is demonstrating.

That being said, I can still assist with getting the outcome you want. I have opened a pull request to your repository with the finished modifications of your YAML workflow, but please read what I've shared below to understand the changes.

https://github.com/PramodKumarHK89/MicrosoftIdentityPlatformEditor/pull/1

Workflow Asset Upload

Ultimately, you only need upload the the contents of the MicrosoftIdentityPlatformEditor\bin\Release\netcoreapp3.1\publish\win-x64 folder after it is finished building.

Here is the GitHub Action that does the asset upload https://github.com/actions/upload-artifact. As you can see you can use a filename, a directory name or a wildcard.

Single-file application

However, if you only want to copy out only the exe (instead of the entire folder), you also need to set the publish command to produce a single file. This is done by passing in the following parameter -p:PublishSingleFile=true.

Here is the build result when using self-contained and single-file exe:

image

For more information, please read https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file/overview#publish-a-single-file-app---cli

Moving Forward & Creating a Tagged Release

Walking you through how to use Releases on GitHub is a bit outside the scope of this example, but I've added some steps to the bottom of the workflow that you can experiment with to get started,

If you have any trouble with creating a tagged release, StackOverflow and Microsoft Q&A are great resources with fast responses on general topics like that.

PramodKumarHK89 commented 2 years ago

Thank you @LanceMcCarthy for the quick turn around. Appreciated.