在 Visual Studio 2017 年使用 Web 部署发布 ASP.NET Core 2.1/Angular 应用程序不会将 ClientApp/dist 文件夹复制到主机
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
我想我已经把标题中的问题总结得差不多了。详情如下:
启动:
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");
}
});
}
以上代码大部分是Visual Studio我新建项目时生成的。
然后,如果我手动复制 dist 文件夹,它就可以完美运行。我错过了什么?
<SpaRoot>ClientApp\</SpaRoot>
核心项目的 csproj 文件中缺少。
我想我已经把标题中的问题总结得差不多了。详情如下:
启动:
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");
}
});
}
以上代码大部分是Visual Studio我新建项目时生成的。 然后,如果我手动复制 dist 文件夹,它就可以完美运行。我错过了什么?
<SpaRoot>ClientApp\</SpaRoot>
核心项目的 csproj 文件中缺少。