我尝试了几种不同的方法来设置此项目,但每种方法均失败。这是我的问题。
这是我的startup.cs代码:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddNewtonsoftJson();
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "client/build";
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseRouting(routes =>
{
routes.MapControllers();
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "client";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
app.UseAuthorization();
}
}
运行此命令时, spa.UserReactDevelopmentServer(npmScript:“ start”)所在的行会不断抛出错误。错误是:
{“找不到方法:'无效Microsoft.Extensions.Logging.Console.ConsoleLogger..ctor(System.String,System.Func`3,Boolean)'。“}
有没有人知道如何使用React前端(不是类型脚本版本)创建一个.NET Core 3.0 WebAPI,当您点击播放时(VS 2019中的绿色继续按钮),它们都将运行React,并且仍然API部分在调用时可以正常工作。对于清酒而言,这应该不难!
答案 0 :(得分:2)
我有同样的问题。
将项目.csproj中的“ Microsoft.AspNetCore.SpaServices.Extensions”的参考更改版本更改为“ 3.0.0-preview8.19405.4”对我有用。