【问题标题】:How do I fix the error "The specified deps.json [] does not exist" for a .NET 6 Web Assembly app using EF and SQLite?如何修复使用 EF 和 SQLite 的 .NET 6 Web Assembly 应用程序的错误“指定的 deps.json [] 不存在”?
【发布时间】:2023-02-01 14:24:00
【问题描述】:

我正在使用 Entity Framework 和 SQLite 构建 NET 6 Blazor Web Assembly 应用程序。当我尝试将初始迁移添加到数据库时,出现错误 "The specified deps.json [C:\git\ThePlayer\ThePlayer\Client\bin\Debug\net6.0\ThePlayer.Client.deps.json] does not exist"

我的客户端 (WASM) 项目中有以下参考资料:

  <ItemGroup>    
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.12" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.12" PrivateAssets="all" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="6.0.12" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.12">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.3" />
  </ItemGroup>

这是包含所有代码的 github 存储库:https://github.com/tysongibby/ThePlayer

重建项目时在输出中收到以下警告:

Rebuild started...
1>------ Rebuild All started: Project: ThePlayer.Shared, Configuration: Debug Any CPU ------
Restored C:\git\ThePlayer\ThePlayer\Server\ThePlayer.Server.csproj (in 43 ms).
Restored C:\git\ThePlayer\ThePlayer\Client\ThePlayer.Client.csproj (in 44 ms).
Restored C:\git\ThePlayer\ThePlayer\Shared\ThePlayer.Shared.csproj (in 43 ms).
1>ThePlayer.Shared -> C:\git\ThePlayer\ThePlayer\Shared\bin\Debug\net6.0\ThePlayer.Shared.dll
2>------ Rebuild All started: Project: ThePlayer.Client, Configuration: Debug Any CPU ------
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning : Found a native function (sqlite3_config) with varargs in e_sqlite3. Calling such functions is not supported, and will fail at runtime. Managed DllImports: 
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_config_none(System.Int32) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_config_int(System.Int32, System.Int32) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_config_int_arm64cc(System.Int32, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.Int32) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_config_log(System.Int32, System.IntPtr, SQLitePCL.hook_handle) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_config_log_arm64cc(System.Int32, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, SQLitePCL.hook_handle) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning : Found a native function (sqlite3_db_config) with varargs in e_sqlite3. Calling such functions is not supported, and will fail at runtime. Managed DllImports: 
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_charptr(SQLitePCL.sqlite3, System.Int32, System.Byte*) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_charptr_arm64cc(SQLitePCL.sqlite3, System.Int32, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.Byte*) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_int_outint(SQLitePCL.sqlite3, System.Int32, System.Int32, System.Int32*) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_int_outint_arm64cc(SQLitePCL.sqlite3, System.Int32, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.Int32, System.Int32*) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_intptr_int_int(SQLitePCL.sqlite3, System.Int32, System.IntPtr, System.Int32, System.Int32) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.12\Sdk\WasmApp.Native.targets(244,5): warning :     System.Int32 sqlite3_db_config_intptr_int_int_arm64cc(SQLitePCL.sqlite3, System.Int32, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr, System.Int32, System.Int32) (in [SQLitePCLRaw.provider.e_sqlite3] SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods)
2>Compiling native assets with emcc. This may take a while ...
2>[1/3] pinvoke.c -> pinvoke.o [took 0.38s]
2>[2/3] corebindings.c -> corebindings.o [took 0.46s]
2>[3/3] driver.c -> driver.o [took 0.56s]
2>Linking with emcc. This may take a while ...
2> "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\bin\wasm-ld.exe" -o C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\dotnet.wasm C:\Users\tyson.LAPPY9000\.nuget\packages\sqlitepclraw.lib.e_sqlite3\2.1.3\buildTransitive\net6.0\..\..\runtimes\browser-wasm\nativeassets\net6.0\e_sqlite3.a C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\pinvoke.o C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\driver.o C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\corebindings.o "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libicui18n.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libicuuc.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-component-debugger-static.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-component-diagnostics_tracing-stub-static.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-component-hot_reload-static.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-ee-interp.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-icall-table.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-ilgen.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmono-profiler-aot.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libmonosgen-2.0.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libSystem.IO.Compression.Native.a" "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\6.0.12\runtimes\browser-wasm\native\libSystem.Native.a" "-LC:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libgl.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libal.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libhtml5.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++abi.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libdlmalloc.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\cache\sysroot\lib\wasm32-emscripten\libsockets.a" -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --export putchar --export stackSave --export stackRestore --export stackAlloc --export __wasm_call_ctors --export __errno_location --export malloc --export free --export __cxa_is_pointer_type --export __cxa_can_catch --export setThrew --export _get_tzname --export _get_daylight --export _get_timezone --export memalign --export memset --export emscripten_main_thread_process_queued_calls --export ntohs --export htons --export htonl --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-table -z stack-size=5242880 --initial-memory=536870912 --no-entry --max-memory=2147483648 --global-base=1024
2> "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\bin\wasm-emscripten-finalize" --minimize-wasm-changes -g --dyncalls-i64 --dwarf C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\dotnet.wasm -o C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\dotnet.wasm --detect-features
2> "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Node.win-x64\6.0.12\tools\bin\node.exe" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\emscripten\src\compiler.js" C:\Users\TYSON~1.LAP\AppData\Local\Temp\tmppxf580an.txt
2> "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.12\tools\bin\llvm-objcopy.exe" C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\dotnet.wasm C:\git\ThePlayer\ThePlayer\Client\obj\Debug\net6.0\wasm\for-build\dotnet.wasm --remove-section=producers
2>Optimizing dotnet.wasm ...
2>ThePlayer.Client -> C:\git\ThePlayer\ThePlayer\Client\bin\Debug\net6.0\ThePlayer.Client.dll
2>ThePlayer.Client (Blazor output) -> C:\git\ThePlayer\ThePlayer\Client\bin\Debug\net6.0\wwwroot
2>Done building project "ThePlayer.Client.csproj".
3>------ Rebuild All started: Project: ThePlayer.Server, Configuration: Debug Any CPU ------
3>ThePlayer.Server -> C:\git\ThePlayer\ThePlayer\Server\bin\Debug\net6.0\ThePlayer.Server.dll
========== Rebuild All: 3 succeeded, 0 failed, 0 skipped ==========
========== Elapsed 00:18.020 ==========

【问题讨论】:

  • 您的 git 仓库引用了仓库外部的代码。丢失的项目阻止任何人重现您的问题。
  • @stefan.seeland 感谢您查看我的问题并注意到该问题。我已经更新代码以引用必要的 nuget 包,而不是 nuget 项目。它现在将用于重现该问题。
  • 在 github repo github.com/ericsink/SQLitePCL.raw/issues/533 与作者一起打开了一个问题
  • SQLLitePCL.raw 指示我在 EntityFramework 团队的 GitHub 存储库上提出问题。

标签: c# sqlite entity-framework-core .net-6.0 blazor-webassembly


【解决方案1】:

我向 Entity Framework 团队开了一张票,他们为这个问题提供了这个解决方法:

解决方法是在解决方案中创建一个单独的控制台应用程序项目。该项目仅用于使 EF 工具能够创建适当的上下文实例。该项目需要引用包含您的 DbContext 和您正在使用的 EF Core 数据库提供程序的项目。例如:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="6.0.12" />
        <PackageReference Include="SQLitePCLRaw.core" Version="2.1.3" />
        <PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="2.1.3" />
        <PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.1.3" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..ThePlayerSharedThePlayer.Shared.csproj" />
    </ItemGroup>

</Project>

控制台应用程序需要有一个IDesignTimeDbContextFactory。是这样的:

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using ThePlayer.Shared.Data.Context;

Console.WriteLine("Hello, World!");

public class ContextFactory : IDesignTimeDbContextFactory<ThePlayerContext>
{
    public ThePlayerContext CreateDbContext(string[] args) 
        => new(null, new DbContextOptionsBuilder<ThePlayerContext>().UseSqlite(args[0]).Options);
}

然后可以使用它从命令行生成迁移。例如:

PS C:localcode
eprosThePlayer-masterThePlayer-masterConsoleApp1> dotnet ef migrations add One --project ..ThePlayerSharedThePlayer.Shared.csproj -- "DataSource=ThePlayer.db"
Build started...
Build succeeded.
Done. To undo this action, use 'ef migrations remove'
PS C:localcode
eprosThePlayer-masterThePlayer-masterConsoleApp1>

来源:How do generate migrations for an Blazor WASM

【讨论】:

    猜你喜欢
    • 2023-02-01
    • 1970-01-01
    • 2017-05-26
    • 2020-05-27
    • 2020-02-01
    • 2020-12-13
    • 2019-10-10
    • 1970-01-01
    • 2019-11-11
    相关资源
    最近更新 更多