【发布时间】:2019-01-28 02:39:04
【问题描述】:
两个不同的网络应用程序。两者都从 asp.net core w/angular 模板开始。在第二种情况下,我生成了一个 angular6 应用程序。 angular6 应用程序在本地运行良好。它是 Visual Studio 的发布步骤,在第二种情况下事情会横向发展。
(1) 一个使用 asp.net core w/angular 5 模板的测试用例。工作正常,发布到本地 IIS 网站,也可以正常工作。发布到 IIS 时,我得到了“ClientApp”文件夹
package.json 脚本部分
"name": "aspnetcore_dummy1",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --extract-css",
"build": "ng build --extract-css",
"build:ssr": "npm run build -- --app=ssr --output-hashing=media",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
来自 tsconfig.json
"compilerOptions": {
"outDir": "./dist/out-tsc",
(2)
带 Angular 6 的 asp.net 核心应用程序
project.json 脚本部分
"name": "client-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
来自 tsconfig.json
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
在这两种情况下,这都是 Startup.cs 对于 ConfigureServices 的样子
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
}
但是,当发布到 IIS 时,情况 (1) 对 ClientApp/dist 文件夹是正确的,但 (2) 我没有得到 ClientApp 下的“dist”文件夹,而是“e2e”、“src”文件夹和一些的设置文件。看图
[更新] - csproj 文件中的内容有效,但不在其他 csproj 文件中
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
<DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
【问题讨论】:
-
1.您能否向我们展示您项目的
csproj文件? 2. 发布项目时,会执行npm install,npm run build,...等cmds。那么当你运行命令dotnet publish -c Release时输出是什么? -
@itminus - 是的,我认为这就是存在一些差异的地方。请参阅帖子底部的更新。现在我不记得我是否从带有角度模板的 asp.net 核心开始或不用于项目 (2) - 有发布问题的项目。现在回想起来,我觉得我没有。相反,我从一个空白的 asp.net 核心网络应用程序开始。
标签: angular iis asp.net-core iis-express