5

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!!

4
  • For asp.net core with react, you could create with Asp.Net Core React template directly from VS 2019. Do you have any issue with this template? Commented Jul 1, 2019 at 6:16
  • I tried that, when generating the solution, react is created with typescript, if I remove that with create-react-app, it fails as well. I'm really confused as to why the solution gets messed up when adding a new file with the dotnet new react command prompt way Commented Jul 1, 2019 at 12:33
  • Check your project.csproj. For default react template, there are many tasks in the .csproj file for combining the react and .net core project. Commented Jul 2, 2019 at 6:41
  • So here is my issue, if I open VS 2019, create a new .NET core 3.0 web application and say it is a React application (earlier versions of VS would allow you to also click on Web API but they stopped doing that) so the controller is a MVC controller. If I run this as is, it works fine. If I add a Web API controller and that is it, I click run and the application now crashes. I altered nothing, it was working before but it cannot handle adding a new file. What the hell is wrong with..net core 3?? Commented Jul 2, 2019 at 12:07

1 Answer 1

6

I had the same issue.

Changing version of reference for "Microsoft.AspNetCore.SpaServices.Extensions" in project .csproj to "3.0.0-preview8.19405.4" worked for me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.