Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSIX packaging for arbitrary .NET project types #4932

Open
daniel-lerch opened this issue Dec 3, 2024 · 6 comments
Open

MSIX packaging for arbitrary .NET project types #4932

daniel-lerch opened this issue Dec 3, 2024 · 6 comments

Comments

@daniel-lerch
Copy link

Motivation

The .NET SDK supports streamlined MSIX publishing for WinUI 3 and MAUI projects. For other project types one can use an application packaging project. Packaging projects are cumbersome to use, more complicated to use than dotnet in CI pipeline and cannot pass MSBuild properties to child projects easily.

Desired solution

I would like to have MSIX packaging tools for arbitrary .NET project types including Avalonia, WPF, WinForms, Console. It should be compatible with other features like single file executable, trimming and Native AOT.

Additional context

I originally posted this issue at dotnet/sdk#45045. However, as @Sergio0694 pointed out, MSIX packaging functionality is already implemented in Microsoft.Windows.SDK.BuildTools.MSIX and could be extended to support other frameworks than WinUI 3 or MAUI. Unfortunately, I could not find the source code for that NuGet package and hope that I am not totally wrong by opening this issue here.

@Sergio0694
Copy link
Member

"could be extended to support other frameworks than WinUI 3 or MAUI"

Note, UWP (on .NET 9) also uses that package, so it's already the case that it supports several different frameworks. The MSIX tooling itself doesn't really care about the UI framework in the first place. Have you tried using it with an Avalonia/WPF/WinForms app already, as a test? Did you get any errors in particular? Knowing that could be useful as a starting point 🙂

cc. @Scottj1s

@daniel-lerch
Copy link
Author

daniel-lerch commented Dec 3, 2024

Single project MSIX packaging works „out of the box“ for WinForms 🤯

I created a Blank App, Packaged (WinUI 3 in Desktop) and copied over the Assets folder, Properties folder including launchSettings.json and PublishProfiles and almost the entire project file to a Windows Forms project and it works in Visual Studio.

When I tested this before opening this issue I used only the online documentation for MAUI MSIX packaging and did not use samples from project templates which did not work.

Current state of tested project types and configurations (all without reference to Microsoft.WindowsAppSDK):

  • ✅ WinForms
  • ✅ Avalonia
  • ✅ Invocation via MSBuild.exe
  • PublishSingleFile
  • PublishReadyToRun
  • PublishAot
  • ❌ Build AnyCPU e.g. for unit test project
  • ❌ Package and publish from Visual Studio

If everything works, I will close this issue and open issues at the respective docs repositories to inform developers about this amazing feature.

@Sergio0694
Copy link
Member

Sergio0694 commented Dec 3, 2024

This aligns with what I was expecting, and it was one of the reasons why we decoupled the MSIX tooling in its own package 🙂
You should be able to just add a package reference to it, set EnableMsixTooling, and that's it. Don't even need WinAppSDK.

@DarranRowe
Copy link

@Sergio0694

Just to clarify, is this an official statement that this package is supported in arbitrary projects? If it is, where can we find the documentation, or if it doesn't exist yet, when can we expect the documentations?

@Sergio0694
Copy link
Member

It's not an official statement, no. Right now, the package is only officially supported for UWP, and it will be officially supported for WinUI 3 when WinAppSDK switches to it as well in a future release. I will see if we can add documentation to make this overall support official though. I'm just saying in the meantime, people can try it out on other frameworks (eg. WinForms, WPF), and it should work fine, in theory 🙂

@daniel-lerch
Copy link
Author

daniel-lerch commented Dec 4, 2024

You should be able to just add a package reference to it, set EnableMsixTooling, and that's it. Don't even need WinAppSDK.

That's right. I can build and deploy arbitrary projects as MSIX using Visual Studio's launch configuration.

However, I faced a few problems:

  1. Visual Studio's package and publish context menu works only when using Microsoft.WindowsAppSdk instead of Microsoft.Windows.SDK.BuildTools.MSIX. Setting HasPackageAndPublishMenu and <ProjectCapability Include="Msix" /> have no effect on that.
  2. Microsoft.Windows.SDK.BuildTools.MSIX ignores PublishSingleFile in publish profiles whereas WinAppSDK produces an error: PublishSingleFile only supports unpackaged apps
  3. Microsoft.Windows.SDK.BuildTools.MSIX fails to build with PublishReadyToRun:
"C:\Users\***\source\vocup\src\Vocup.WinForms\Vocup.WinForms.csproj" (Standardziel) (1) ->
(_ComputeAppxPackagePayload Ziel) ->
  C:\Users\***\.nuget\packages\microsoft.windows.sdk.buildtools.msix\1.1.20241024.1\build\Microsoft.Windows.SDK.Build
Tools.MSIX.Packaging.targets(1791,5): error APPX1101: Payload contains two or more files with the same destination path
 'Vocup.WinForms.dll'. Source files:  [C:\Users\***\source\vocup\src\Vocup.WinForms\Vocup.WinForms.csproj]
C:\Users\***\.nuget\packages\microsoft.windows.sdk.buildtools.msix\1.1.20241024.1\build\Microsoft.Windows.SDK.BuildTo
ols.MSIX.Packaging.targets(1791,5): error APPX1101: C:\Users\***\source\vocup\src\Vocup.WinForms\bin\x64\Release\net9
.0-windows10.0.22621.0\win-x64\Vocup.WinForms.dll [C:\Users\***\source\vocup\src\Vocup.WinForms\Vocup.WinForms.csproj
]
C:\Users\***\.nuget\packages\microsoft.windows.sdk.buildtools.msix\1.1.20241024.1\build\Microsoft.Windows.SDK.BuildTo
ols.MSIX.Packaging.targets(1791,5): error APPX1101: C:\Users\***\source\vocup\src\Vocup.WinForms\obj\x64\Release\net9
.0-windows10.0.22621.0\win-x64\R2R\Vocup.WinForms.dll [C:\Users\***\source\vocup\src\Vocup.WinForms\Vocup.WinForms.cs
proj]
  1. Project fails to build for arch AnyCPU with Microsoft.Windows.SDK.BuildTools.MSIX.
C:\Users\***\.nuget\packages\microsoft.windows.sdk.buildtools.msix\1.1.20241024.1\build\Microsoft.Windows.SDK.BuildTools.MSIX.Packaging.targets(1067,5): error : Packaged .NET applications with an app host exe cannot be ProcessorArchitecture neutral. Please specify a RuntimeIdentifier or a Platform other than AnyCPU.
  1. When building in Visual Studio, I ocassionally get an error (MSB4062) which I was not able to reproduce so far.
The "Microsoft.Build.Msix.Recipe.WinAppSdkMatchItemsByFileNameOnMetadataValue" task could not be loaded from the assembly C:\Users\***\.nuget\packages\microsoft.windows.sdk.buildtools.msix\1.1.20241024.1\build\..\tools\net472\Microsoft.Build.Msix.dll.
Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants