两个不同的Web应用程序,都是从asp.net core w / angular模板开始。在第二种情况下,我生成了一个angular6应用程序。该angular6应用程序在本地运行良好。在第二种情况下,从Visual Studio发布步骤出现问题。
(1)使用asp.net core w / angular 5模板的测试用例。运行正常,可以发布到本地IIS网站并在那里正常工作。在发布到IIS时,我得到了“ClientApp”文件夹。 package.json脚本部分
在这两种情况下,Startup.cs在ConfigureServices方面的外观如下。
然而,当发布到IIS时,情况(1)在ClientApp/dist文件夹下是正确的,但是(2)我没有在ClientApp下获得'dist'文件夹,而是'e2e','src'文件夹和一些设置文件。请参见图像。
(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)
asp.net core应用程序和Angular 6一起使用的项目.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>
csproj
文件?npm install
,npm run build
等命令。那么当您运行dotnet publish -c Release
命令时,输出是什么?