microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.84k stars 320 forks source link

Self contained publish fails when using winappsdk 1.1 and microsoft.identity.client #2492

Open jmiddour opened 2 years ago

jmiddour commented 2 years ago

Describe the bug

When trying to publish a self contained app using windows app sdk 1.1 preview 2 and Microsoft Identity Client 4.43.2 I'm getting an error: image

I think the issue is that the publish isn't picking up that the file is already requested. I've tried suppressing duplicate file errors and setting an itemgroup remove for it, but nothing has worked so far.

ideas?

Steps to reproduce the bug

Create a new winui3 desktop app. Add a winui3 class library that the app references add the microsoft identity client to the class library attempt to publish the app

Expected behavior

No response

Screenshots

No response

NuGet package version

1.1.0-preview1

Packaging type

Packaged (MSIX)

Windows version

Windows 10 version 2004 (19041, May 2020 Update)

IDE

Visual Studio 2022-preview

Additional context

No response

mikebattista commented 2 years ago

This may be a duplicate of https://github.com/microsoft/WindowsAppSDK/issues/1856. Could you take a look at that and see if it's the same issue?

jmiddour commented 2 years ago

@mikebattista based on the thread, it is similar but doesn't appear to be the same. I do not have the private assets or runtime includes specified. I'm including the package reference section of the library project: image If there is another possible work around, I'm willing to try it. As far as I can tell the Identity client is the only thing actively using the webview2 dll.

jmiddour commented 2 years ago

I possibly found a work around based on what was mentioned in the other thread(s) ... If I add

<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1185.39">
      <ExcludeAssets>compile;runtime</ExcludeAssets>
    </PackageReference>

to my application project, I get past the error I had above. However, it now fails because it cannot find the dll of my library project because it is looking in a runtime folder that the compile didn't output to. it is looking for the dll here: image instead of where it was actually output, here: image

mikebattista commented 2 years ago

Also when you say self-contained "publish", are you doing dotnet publish? Or something else?

jmiddour commented 2 years ago

The errors above were when I did a right click, publish on the application project in visual studio. That ultimately isn't the typical app deployment method, so it may end up being behavior not supported in the long run.

When I try generating the app packages option, VS2022 17.3-preview 1 crashed. I made sure everything I could find was updated appropriately and it still crashed every time.

I did finally get a msix built from the command line, so I have something working now. I'll be refining what i've done so far, so I may have more/better info over the next couple weeks.

mikebattista commented 2 years ago

Thanks. dotnet publish which is also what the Publish... dialog uses is not supported yet with WinAppSDK. If this is an MSIX project, you want to use the Package and Publish -> Create App Packages... dialog instead from the same project context menu. Could you try that? If the app is configured to be self-contained, that content should be carried within the MSIX package.

jmiddour commented 2 years ago

When I try create app packages, visual studio crashes entirely -- no dialog/wizard shows; just a crash report to MS followed by a vs restart.

mikebattista commented 2 years ago

I have hit this too in the past and debugged with VS. There's a hidden .suo file under <SOLUTION>/.vs/<APPNAME>/v17/ and also potentially a .csproj.user right next to the .csproj. Could you back those up somewhere, then delete those files and try again?

jmiddour commented 2 years ago

I deleted all .vs/.user/bin/obj directories entirely. Now when I try it, it still crashes but Visual Studio will let me throw it to debug.

Here is the exception details from the debugger:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Microsoft.VisualStudio.AppxPackage
  StackTrace:
   at Microsoft.VisualStudio.AppxPackage.PublishAppXViewModelBase.<>c__DisplayClass23_0.<<GetUserBoolSetting>b__0>d.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
   at Microsoft.VisualStudio.Threading.JoinableTask`1.CompleteOnCurrentThread()
   at Microsoft.VisualStudio.AppxPackage.PublishAppXViewModelBase.GetUserBoolSetting(String name, Boolean defaultValue)
   at Microsoft.VisualStudio.AppxPackage.PickProductViewModel.LoadUserSettingsOrDefault()
   at Microsoft.VisualStudio.AppxPackage.PickProductViewModel..ctor(PublishAppXResult result)
   at Microsoft.VisualStudio.AppxPackage.PackageDialog.PublishAppXNavigationFactory.CreateNavigationTree(IPageNavigator nav, INavigationPageHost host)
   at Microsoft.VisualStudio.WizardFrameworkWpf.WizardBase.InitializeInternal(INavigationTreeFactory navigationTreeFactory)
   at Microsoft.VisualStudio.AppxPackage.Commands.Packaging.<PackageAppxMenuItemExec>d__27.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

  This exception was originally thrown at this call stack:
    Microsoft.VisualStudio.AppxPackage.PublishAppXViewModelBase.GetUserBoolSetting.AnonymousMethod__0()
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
    Microsoft.VisualStudio.AppxPackage.PublishAppXViewModelBase.GetUserBoolSetting(string, bool)
    Microsoft.VisualStudio.AppxPackage.PickProductViewModel.LoadUserSettingsOrDefault()
    Microsoft.VisualStudio.AppxPackage.PickProductViewModel.PickProductViewModel(Microsoft.VisualStudio.AppxPackage.PublishAppXResult)
    Microsoft.VisualStudio.AppxPackage.PackageDialog.PublishAppXNavigationFactory.CreateNavigationTree(Microsoft.VisualStudio.WizardFrameworkWpf.IPageNavigator, Microsoft.VisualStudio.WizardFrameworkWpf.INavigationPageHost)
    Microsoft.VisualStudio.WizardFrameworkWpf.WizardBase.InitializeInternal(Microsoft.VisualStudio.WizardFrameworkWpf.INavigationTreeFactory)
    Microsoft.VisualStudio.AppxPackage.Commands.Packaging.PackageAppxMenuItemExec(object, System.EventArgs)
    ...
    [Call Stack Truncated]

I'm happy to help if you want to continue to trace this down, but please keep in mind -- I'm running preview VS with preview WinAppSDK and could very well have messed something up in my install by adding or removing extensions from the early winappsdk builds. In other words, I wouldn't be shocked if this particular issue was not reproducible.

I was much more concerned about the other issues that we've already addressed as at least relatively known -- even if it wasn't clear to me that they were related initially.

mikebattista commented 2 years ago

Thanks. Yes that is exactly the known issue I have hit and is specific to the 1.1 preview release. VS is investigating. It's not a 100% repro and the workaround for me was to remove both the .suo and csproj.user files I mentioned, but I've heard that doesn't always work. If you hit this and need to produce an MSIX, you can do so from the command line with tools like makeappx.

Regarding the original APPX1101 issue, we are investigating that.

mikebattista commented 2 years ago

I'm following up with the WebView2 team on this issue. It's definitely WebView2 specific and not the same as the other issue I linked, given it's included in WinAppSDK but also pulled in as a transitive dependency from the identity client library.

keithbo1961 commented 2 years ago

Did this issue ever get resolved? I am using WinAppSDK 1.1.5 and still getting the msix duplication failure with WebView2.

NeilQ commented 1 year ago

Same issue about msix webview2 when using Microsoft.Data.SqlClient >=5.00, and works with Microsoft.Data.SqlClient 4.1.1

rossirpaulo commented 1 year ago

No updates?

kmgallahan commented 1 year ago

@mikebattista @bpulliam This is still a problem.