提问人:Lena 提问时间:9/6/2023 更新时间:9/6/2023 访问量:37
将 Blazor 组件与项目类型“类库”中的 Sdk Microsoft.Net.Sdk 集成
Integrate Blazor components with Sdk Microsoft.Net.Sdk in the project type "class library"
问:
是否可以将 Blazor 组件集成到 Microsoft.Net.Sdk 类库项目中。目标:net7.0。它是Nocommerce框架中的自定义插件。
如果我尝试使用新的 MVC Web 项目 (Microsoft.NET.Sdk.Web),一切都运行良好。
我做的步骤:
- .csproj 文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AssemblyName>Nop.Plugin.Test</AssemblyName>
<RootNamespace>Nop.Plugin.Test</RootNamespace>
<Company>Test</Company>
<OutputPath>..\..\..\..\test\src\Presentation\Nop.Web\Plugins\Test.Web</OutputPath>
<OutDir>$(OutputPath)</OutDir>
<OutNopWeb>$(OutDir)\..\..</OutNopWeb>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<NoWarn>1701;1702;IL2121;NETSDK1138</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.0" />
</ItemGroup>
<PropertyGroup>
<RazorLangVersion>7.0</RazorLangVersion>
</PropertyGroup>
<ItemGroup>
<!-- Include your Blazor components here -->
<RazorCompile Include="$(OutNopWeb)\Themes\Test\**\*.razor" />
</ItemGroup>
</Project>
- 启动.cs,配置方法:
public void Configure(IApplicationBuilder app)
{
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapBlazorHub();
});
}
- 启动.cs 配置服务方法:
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddServerSideBlazor();
}
- Layout.cshtml
<base href="~/" />
<script src="_framework/blazor.server.js"></script>
- 索引.cshtml
@(await Html.RenderComponentAsync<Nop.Plugin.Test.Web.Themes.Views.Shared.RazorComponents.Component>(RenderMode.ServerPrerendered, new { Data = " Hello World " }))
答: 暂无答案
评论