I have tried a couple of different ways to set up this project and each one fails. Here are my issues.
- Using command prompts to creating these projects as directed in this article has one major flaw, if you generate these, then open it up in VS 2019, you can run it out of the box, no issues. The SECOND you add a file, it will prompted you to save a solution file, after that, the entire solution crashes and you can no longer launch it.... so this option seems hosed.
- I tried to create a .net core 3 application with VS 2019, making it a WebAPI application. After that, I went into the root directory and by command prompt wrote: npx create-react-app client which appeared to create the project correctly. After that, I went to the startup.cs file added the spa items needed for it to run (added NuGet package Microsoft.AspNetCore.SpaServices.Extensions)
Here is my startup.cs code:
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();
}
}
When I run this, the line where spa.UserReactDevelopmentServer(npmScript: "start") keeps throwing an error. The error is:
{"Method not found: 'Void Microsoft.Extensions.Logging.Console.ConsoleLogger..ctor(System.String, System.Func`3, Boolean)'."}
Does anyone have a clue as to creating a .NET Core 3.0 WebAPI with React front-end (not the type script version) that will both run the React when you hit play (green continue button in VS 2019) AND still have the API part work when calling it. It shouldn't be this hard for God Sake!!
Asp.Net Core React templatedirectly from VS 2019. Do you have any issue with this template?