WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

Payload contains two deps.json

Open sjb-sjb opened this issue 2 years ago • 9 comments

Describe the bug

See EF core github issue 27576. The EF Core team has identified that this is a WinUI issue.

I am using Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Sqlite. My Microsoft.WindowsAppSDK app consists of a packaged app and two libraries using WinUI 3. It compiles fine using VS 2022 Community 17.1.0 But then when I add Microsoft.EntityFrameworkCore.Design, I get this compile error:

Error APPX1101 Payload contains two or more files with the same destination path 'App.deps.json'. Source files: C:\Users[...]\App\obj\x64\Debug\net6.0-windows10.0.19041.0\win10-x64\App.deps.json C:\Users[...]\App\bin\x64\Debug\net6.0-windows10.0.19041.0\win10-x64\App.deps.json

This happens with EFCore version 6.0.0 and 6.0.2.

Steps to reproduce the bug

Steps to reproduce.

  1. Install the configuration shown below and create a solution called Test with a single project called Test, using the project template "Blank App, Packaged (WinUI 3 in Desktop)".
  2. Add references for Microsoft.EntityFrameworkCore 6.0.0 and Microsoft.EntityFrameworkCore.Sqlite 6.0.0
  3. Add the code shown below.
  4. Compile and run
  5. Add a reference for Microsoft.EntityFrameworkCore.Design 6.0.0
  6. Compile and observe the error.

Code

namespace Test
{
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
        }

        private void MyButton_Click(object sender, RoutedEventArgs e)
        {
            myButton.Content = "Clicking...";
            BloggingContext bc = new BloggingContext();
            bc.Database.EnsureCreated();
            bc.Dispose();
            myButton.Content = "Clicked";
        }
    }

    public class BloggingContext : DbContext
    {
        public DbSet<Blog> Blogs { get; set; }
        public DbSet<Post> Posts { get; set; }

        public string DbPath { get; }

        public BloggingContext()
        {
            //string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); 
            Debug.WriteLine($"path: {path}");
            this.DbPath = System.IO.Path.Join(path, "blogging.db");
        }

        // The following configures EF to create a Sqlite database file in the
        // special "local" folder for your platform.
        protected override void OnConfiguring(DbContextOptionsBuilder options)
        {
            options.UseSqlite($"Data Source={this.DbPath}");
        }
    }

    public class Blog
    {
        public int BlogId { get; set; }
        public string Url { get; set; }

        public List<Post> Posts { get; } = new();
    }

    public class Post
    {
        public int PostId { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }

        public int BlogId { get; set; }
        public Blog Blog { get; set; }
    }
}

Configuration

Microsoft Visual Studio Community 2022
Version 17.1.0
VisualStudio.17.Release/17.1.0+32210.238
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Community

Visual C++ 2022   00482-90000-00000-AA995
Microsoft Visual C++ 2022

ASP.NET and Web Tools 2019   17.1.358.51495
ASP.NET and Web Tools 2019

Azure App Service Tools v3.0.0   17.1.358.51495
Azure App Service Tools v3.0.0

C# Tools   4.1.0-5.22109.6+0c82c4114a4e4b8b723b915eee3b13261db6717f
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

NuGet Package Manager   6.1.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

TypeScript Tools   17.0.1229.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.1.0-5.22109.6+0c82c4114a4e4b8b723b915eee3b13261db6717f
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.1.0-beta.21610.4+07b5673e4f2fa7630e78abe37f16b372353a7242
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

Expected behavior

Expected no error on compile.

Screenshots

No response

NuGet package version

No response

Windows app type

  • [ ] UWP
  • [ ] Win32

Device form factor

No response

Windows version

No response

Additional context

No response

sjb-sjb avatar Mar 10 '22 16:03 sjb-sjb

This is being caused by including Microsoft.EntityFrameworkCore.Design as I ran into the same problem with Microsoft.EntityFrameworkCore.Tools.

I reported the problem here: https://github.com/dotnet/efcore/issues/26973

It was stated:

This is being tracked internally.

The same issue applies to both packages. Replying to your other issue to try and get clarity...

Probably also rather a WindowsAppSDK issue rather than WinUI, as reported here:

https://github.com/microsoft/WindowsAppSDK/issues/1856

kmgallahan avatar Mar 10 '22 17:03 kmgallahan

There is a workaround in the WindowsAppSDK issue 1856

sjb-sjb avatar Mar 11 '22 01:03 sjb-sjb

see workarround: https://github.com/microsoft/WindowsAppSDK/issues/2524#issuecomment-1129733373

Ika59 avatar May 18 '22 09:05 Ika59

Hello, we are trying to migrate a Xamarin App to MAUI. We don't use entity Framework and are running into the exact same problem of two .deps.json files being generated. Is there any progress in this matter or a workaround I could use? I already posted on issue https://github.com/microsoft/WindowsAppSDK/issues/1856

rxDietel avatar Aug 22 '22 08:08 rxDietel

MAUI app. Just started giving me this error. Nothing changed - just put my machine in hibernate. Came back and the thing won't build

FrankSzendzielarz avatar Aug 28 '22 13:08 FrankSzendzielarz

I actually managed to work around this just by going into the MAUI output folder obj\Debug\net6.0-windows10.0.19041.0 and deleting the deps.json. The issue is the build task considers the bin and obj deps.json files as identical and throws an error that they are dups.

FrankSzendzielarz avatar Aug 28 '22 14:08 FrankSzendzielarz

I am having MAUI issues aswell. But the moment i fix this error, i can't use the ADD-Migration command anymore. I keep getting an Android not supported error

MessiasRu avatar Sep 06 '22 13:09 MessiasRu

Shouldn't there be a dedicated MAUI issue open for this? I'm not using EF core, hence the workarounds are not applicable to my application as far as I can see...

noffett avatar Sep 15 '22 06:09 noffett

Shouldn't there be a dedicated MAUI issue open for this? I'm not using EF core, hence the workarounds are not applicable to my application as far as I can see...

OK, my bad. In our case it was an auto generated version and package version that caused the problem. image Excluding this from the MAUI build solved the issue.

noffett avatar Sep 15 '22 12:09 noffett

This is fixed in Windows App SDK 1.2 Preview 2. For a workaround, see: https://github.com/microsoft/WindowsAppSDK/issues/1856#issuecomment-1262705228

Scottj1s avatar Sep 29 '22 21:09 Scottj1s

@Scottj1s with all do respect, this is wrong, it is sep 2023 and I am using the latest of everything but still facing the same problem

HakamFostok avatar Sep 28 '23 08:09 HakamFostok

@HakamFostok thanks - do you have a repro we can investigate?

Scottj1s avatar Mar 12 '24 00:03 Scottj1s

We have a repro now, reopening this issue.

Scottj1s avatar Mar 12 '24 17:03 Scottj1s

We've root caused a problem with conflicting deps.json files across project references. A fix will be included in the next release of Windows App SDK. Meanwhile, here is a workaround you can add to your *.csproj file:

  <!-- Temporary workaround until WinAppSDK includes fix -->
  <Target Name="RemoveConflictingDepsJsonFiles" AfterTargets="GetPackagingOutputs">
    <!-- If conflicting build and publish deps.json files exist in this or referenced projects,
        use only the publish deps.json files, and remove the corresponding build deps.json files. -->
    <ItemGroup>
      <_PublishPackagingOutputs Include="@(PackagingOutputs->HasMetadata('CopyToPublishDirectory'))"/>
      <_PublishDepsJsonFiles Include="@(_PublishPackagingOutputs)"
        Condition="'@(_PublishPackagingOutputs)' != '' and $([System.String]::Copy(%(FileName)%(Extension)).EndsWith('.deps.json'))" />
      <PackagingOutputs Remove="@(_PublishDepsJsonFiles)" MatchOnMetadata="TargetPath"/>
      <PackagingOutputs Include="@(_PublishDepsJsonFiles)"/>
    </ItemGroup>
  </Target>

Scottj1s avatar Mar 13 '24 22:03 Scottj1s