gpt4 book ai didi

Blazor WASM 项目引用错误(BLAZORSDK1001)

转载 作者:行者123 更新时间:2023-12-04 17:18:32 25 4
gpt4 key购买 nike

我有一个服务器项目,现在正试图将其转换为渐进式 Web 应用程序。当我向它引用 API、模型和 UI 项目时,会出现以下错误:

<Target Name="_FailIfReferencingAspNetCoreApp" BeforeTargets="ResolveRuntimePackAssets">
<Error
Code="BLAZORSDK1001"
Text="The project references the ASP.NET Core shared framework, which is not supported by Blazor WebAssembly apps. Remove the framework reference if directly referenced, or the package reference that adds the framework reference."
Condition="'@(FrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App')->Count())' != '0'" />
</Target>

下面的代码是项目的.csproj,有什么我遗漏的吗?

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

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
</PropertyGroup>

<ItemGroup>
<Content Remove="wwwroot\service-worker.js" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Blazored.Toast" Version="3.1.2" />
<PackageReference Include="BlazorInputFile" Version="0.2.0" />
<PackageReference Include="DevExpress.Blazor" Version="20.1.7" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.11" />
<PackageReference Include="Hangfire.Core" Version="1.7.11" />
<PackageReference Include="Hangfire.SqlServer" Version="1.7.11" />
<PackageReference Include="LiquidTechnologies.Blazor.ModalDialog" Version="0.9.7" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview3.20168.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.4" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client.Core" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="QRCoder" Version="1.4.1" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="5.3.0" />
<PackageReference Include="Tewr.Blazor.FileReader" Version="2.0.0.20200" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DataAccess\DataAccess.csproj" />
<ProjectReference Include="..\UI\UI.csproj" />
<ProjectReference Include="..\API\API.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

对于解决这个问题有什么建议吗?

最佳答案

“我有一个服务器项目”有点不清楚,因为我们只能看到 <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> .我假设您不想将 Blazor 服务器应用程序转换为 WebAssembly 应用程序?

项目类型现在是 WebAssembly,但除其他外,您还包括 <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />

您无法直接从浏览器应用程序访问数据库。它不受支持并且不安全(所有客户端都可以访问连接字符串)。

此项目需要拆分为客户端和服务器 (API) 部分。

最好的方法是从完整的 Blazor Wasm + Asp.Net Hosted + Individual Accounts 模板创建一个项目(在临时文件夹中)。它会为您提供一个完整的引用,让您知道什么地方去哪里。

关于Blazor WASM 项目引用错误(BLAZORSDK1001),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67666574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com