简体   繁体   中英

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?

<SpaRoot>ClientApp\</SpaRoot>

核心项目的 csproj 文件中缺少。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM