Search code examples
angularasp.net-corevisual-studio-2017web-deploymentpublish

Publishing an ASP.NET Core 2.1/Angular application with Web Deploy in Visual Studio 2017 doesn't copy ClientApp/dist folder to the host


I think I pretty much summarized the problem in the title. Details below:

Startup:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

    services.AddSpaStaticFiles(configuration =>
    {
        configuration.RootPath = "ClientApp/dist";
    });

    var connectionString = Configuration.GetConnectionString("DefaultConnection");

    services.AddScoped<IDbConnection>(c => new SqlConnection(connectionString));

    RegisterRepositories(services);
    RegisterServices(services);
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Error");
        app.UseHsts();
    }

    app.UseMiddleware<MyCustomMiddleware>();
    app.UseHttpsRedirection();
    app.UseStaticFiles();
    app.UseSpaStaticFiles();

    app.UseMvc(roues =>
    {
        roues.MapRoute(
            name: "default",
            template: "{controller}/{action=Index}/{id?}");
    });

    app.UseSpa(spa =>
    {
        spa.Options.SourcePath = "ClientApp";

        if (env.IsDevelopment())
        {
            spa.UseAngularCliServer(npmScript: "start");
        }
    });
}

The above code was mostly generated by Visual Studio when I created the new project. Then if I copy the dist folder manually it works perfectly. What am I missing?


Solution

  • <SpaRoot>ClientApp\</SpaRoot>
    

    was missing from the core project's csproj file.