Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<PackageReference Include="Microsoft.Maui.Controls" Version="*" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)" />

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

We keep Microsoft.Maui.Controls version as * to ensure the sample app always uses the most recent MuGet release. This allows us to run + test the sample app on the latest version to avoid breaking changes in our library which runs on an older version of Microsoft.Maui.Controls.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wildcard * caused the sample app to resolve Microsoft.Maui.Controls to the latest NuGet version (10.0.90), while every other MAUI package in the repo — including Microsoft.Maui.Controls.Maps, Microsoft.Maui.Core, and the MAUI assemblies pulled in transitively by the CommunityToolkit.Maui.* project references — was pinned to 10.0.60 via $(MauiPackageVersion).

This version mismatch broke the Windows build because both MAUI 10.0.60 and 10.0.90 ship the same framework resource file (Files/Microsoft.Maui/Platform/Windows/Styles/Resources.xbf) but with different content. When the Windows App SDK PRI generator merged resources from both versions, it found the same path with conflicting values, producing:

By pinning the sample to $(MauiPackageVersion) (10.0.60), all MAUI packages resolve to the same version, eliminating the duplicate resource conflict.

<PackageReference Include="CommunityToolkit.Maui.Markup" Version="7.0.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="10.5.0" />
Expand Down
12 changes: 10 additions & 2 deletions src/CommunityToolkit.Maui/Alerts/Snackbar/Snackbar.shared.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Extensions;

namespace CommunityToolkit.Maui.Alerts;

Expand Down Expand Up @@ -34,13 +35,19 @@ public partial class Snackbar : ISnackbar

bool isDisposed;
WeakReference<IView>? weakView;

/// <summary>
/// Initializes a new instance of <see cref="Snackbar"/>
/// </summary>
public Snackbar()
{
#if WINDOWS
if (!AppPackageExtensions.IsPackagedApp)
{
throw new InvalidOperationException($"{nameof(Snackbar)} is not supported on unpackaged Windows apps. {nameof(Snackbar)} requires the app to be packaged (MSIX) because it uses the Windows App SDK AppNotificationManager API. See https://learn.microsoft.com/dotnet/communitytoolkit/maui/alerts/snackbar for more information.")
{
HelpLink = "https://learn.microsoft.com/dotnet/communitytoolkit/maui/alerts/snackbar"
};
}
if (!Options.ShouldEnableSnackbarOnWindows)
{
throw new InvalidOperationException($"Additional setup is required in the Package.appxmanifest file to enable {nameof(Snackbar)} on Windows. Additonally, `{nameof(AppBuilderExtensions.UseMauiCommunityToolkit)}(options => options.{nameof(Options.SetShouldEnableSnackbarOnWindows)}({bool.TrueString.ToLower()});` must be called to enable Snackbar on Windows. See the Platform Specific Initialization section of the {nameof(Snackbar)} documentaion for more information: https://learn.microsoft.com/dotnet/communitytoolkit/maui/alerts/snackbar")
Expand Down Expand Up @@ -166,6 +173,7 @@ public void Dispose()

internal static TimeSpan GetDefaultTimeSpan() => TimeSpan.FromSeconds(3);


void OnShown()
{
IsShown = true;
Expand All @@ -177,4 +185,4 @@ void OnDismissed()
IsShown = false;
weakEventManager.HandleEvent(this, EventArgs.Empty, nameof(Dismissed));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Windows.ApplicationModel;

namespace CommunityToolkit.Maui.Extensions;

// Since MediaElement can't access .NET MAUI internals we have to copy this code here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update comment since it is not only for Media Element

// https://github.com/dotnet/maui/blob/main/src/Essentials/src/AppInfo/AppInfo.uwp.cs
static class AppPackageExtensions
{
static readonly Lazy<bool> isPackagedAppHolder = new(() =>
{
try
{
if (Package.Current is not null)
{
return true;
}
}
catch
{
// no-op
}

return false;
});

static readonly Lazy<string> fullAppPackageFilePathHolder = new(() =>
{
return IsPackagedApp
? Package.Current.InstalledLocation.Path
: AppContext.BaseDirectory;
});

/// <summary>
/// Gets if this app is a packaged app.
/// </summary>
public static bool IsPackagedApp => isPackagedAppHolder.Value;


/// <summary>
/// Gets full application path.
/// </summary>
public static string FullAppPackageFilePath => fullAppPackageFilePathHolder.Value;
}
16 changes: 12 additions & 4 deletions src/CommunityToolkit.Maui/Options.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CommunityToolkit.Maui.Extensions;
using CommunityToolkit.Maui.Views;
#if WINDOWS
using System.Diagnostics;
using Microsoft.Maui.LifecycleEvents;
#endif

Expand Down Expand Up @@ -86,8 +87,15 @@ public void SetShouldEnableSnackbarOnWindows(bool value)

else if (Application.Current.Windows.Count is 1)
{
Microsoft.Windows.AppNotifications.AppNotificationManager.Default.NotificationInvoked += OnSnackbarNotificationInvoked;
Microsoft.Windows.AppNotifications.AppNotificationManager.Default.Register();
if (AppPackageExtensions.IsPackagedApp)
{
Microsoft.Windows.AppNotifications.AppNotificationManager.Default.NotificationInvoked += OnSnackbarNotificationInvoked;
Microsoft.Windows.AppNotifications.AppNotificationManager.Default.Register();
}
else
{
Trace.WriteLine($"{nameof(Alerts.Snackbar)} is not supported on unpackaged Windows apps. {nameof(Alerts.Snackbar)} requires the app to be packaged (MSIX). See https://learn.microsoft.com/dotnet/communitytoolkit/maui/alerts/snackbar for more information.");
}
}
})
.OnClosed((_, _) =>
Expand All @@ -96,7 +104,7 @@ public void SetShouldEnableSnackbarOnWindows(bool value)
{
throw new InvalidOperationException($"{nameof(Application)}.{nameof(Application.Current)} cannot be null when Windows are closed");
}
else if (Application.Current.Windows.Count is 0)
else if (Application.Current.Windows.Count is 0 && AppPackageExtensions.IsPackagedApp)
{
Microsoft.Windows.AppNotifications.AppNotificationManager.Default.NotificationInvoked -= OnSnackbarNotificationInvoked;
Microsoft.Windows.AppNotifications.AppNotificationManager.Default.Unregister();
Expand Down Expand Up @@ -134,4 +142,4 @@ public void SetPopupOptionsDefaults(DefaultPopupOptionsSettings globalPopupOptio
{
DefaultPopupOptionsSettings = globalPopupOptionsSettings;
}
}
}
Loading