AzureAD / microsoft-authentication-library-for-dotnet

Microsoft Authentication Library (MSAL) for .NET
https://aka.ms/msal-net
MIT License
1.41k stars 345 forks source link

[Bug] PackageReference to Microsoft.Web.WebView2 in project causes CoreWebView2 name collision when used with Microsoft.WinUI library in WinUI app #4915

Open matthewacme opened 2 months ago

matthewacme commented 2 months ago

Library version used

4.64.0

.NET version

Microsoft.WindowsAppSDK 1.5.240802000

net8.0-windows10.0.22621.0 ### Scenario PublicClient - desktop app ### Is this a new or an existing app? The app is in production, and I have upgraded to a new version of MSAL ### Issue description and reproduction steps Upgrading to the latest version of the Microsoft.IdentityClient and Microsoft.Identity.Client.Extensions.Msal (version 4.64.0 for both libraries) in a WinUI app built on the Microsoft.WindowsAppSDK 1.5.240802000 causes the following error on Compile. > error CS0433: The type 'CoreWebView2' exists in both 'Microsoft.Web.WebView2.Core.Projection, Version=1.0.2739.15, Culture=neutral, PublicKeyToken=2a8ab48044d2601e' and 'Microsoft.WinUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=de31ebe4ad15742b' downgrade to the previous build and the error goes away. My project doesn't have a reference to the `Microsoft.Web.WebView2.Core.Projection` library, so this reference is getting brought in by MSAL. see the source in [GitHub for the .csproj](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/3a6491722d198b9fa3ee58ed2733b313050b3401/src/client/Microsoft.Identity.Client.Desktop/Microsoft.Identity.Client.Desktop.csproj#L51) ### Relevant code snippets _No response_ ### Expected behavior upgrading to the latest library would not break my WinUI app ### Identity provider Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts) ### Regression worked in 4.63.0 ### Solution and workarounds I've tried everything I can to hide the reference you have added from my projects compile. Until the differing folks and teams at Microsoft can agree on exactly WHERE the WebView2 name spaces are going to live, maybe you could alias it in your project?
iulico-1 commented 2 months ago

@matthewacme, are you trying to enable auth for native AAD auth or B2C /external ID ?

matthewacme commented 2 months ago

@iulico-1 The current build of my app, using the following project definition and package references of

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.19044.0</TargetPlatformMinVersion>
    <LangVersion>latest</LangVersion>
    <RootNamespace>MyRadar.WinUI.Services</RootNamespace>
    <RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
    <UseWinUI>true</UseWinUI>
    <SupportedOSPlatformVersion>10.0.20348.0</SupportedOSPlatformVersion>
    <Platforms>x86;x64;ARM64</Platforms>
    <Nullable>enable</Nullable>
    <ImplicitUsings>disable</ImplicitUsings>
  </PropertyGroup>
...

  <ItemGroup>
      <PackageReference Include="AutoMapper" Version="13.0.1" />
      <PackageReference Include="AzureMapsRestToolkit" Version="7.1.0" />
      <PackageReference Include="Microsoft.Identity.Client" Version="4.63.0" />
      <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240802000" />
      <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
      <PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.8" />
  </ItemGroup>

Allows me to currently USE B2C / external ID, that is we are able to currently allow our users to create and use MSAL to set up B2C registration / login / identity with our AD system.

As soon as I attempt update the Microsoft.Identity.Client to 4.64.0 (from 4.63.0) I get the compile error. Upgrading the other references does not "fix" the issue.

charlesroddie commented 2 months ago

Duplicate of https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/4826

Try WinAppSDK 1.6 which was released just after this issue was posted. https://blogs.windows.com/windowsdeveloper/2024/09/04/whats-new-in-windows-app-sdk-1-6/ "Decoupled WebView2 versioning"

matthewacme commented 1 month ago

@charlesroddie Unfortunately it is not possible to upgrade to the WinAppSDK 1.6. I tried that about 2 weeks ago, and the bugs that upgrade introduced were so extensive that our app would not run.

I filed various bugs with the WinAppSDK team in regards to the issues that were raised with an attempt to upgrade to 1.6.

I'm going to have to wait until at least their next release / bug fix for 1.6 before I can upgrade