c# - 使用 webdeploy 发布 ASP.NET Core 2.1 应用程序,不包括所有视图和应用程序文件夹
问题描述
我正在尝试使用 webdeploy 将我的 .net core 2.1 应用程序部署到 IIS 服务器,但是在发布应用程序之后,没有文件夹和文件,包括来自 wwwroot 之外的发布目录和查看文件夹中的文件夹和文件,我只看到 2 个查看页面和那些视图来自主项目以外的不同库,但没有生成属于主项目的视图。
程序.cs
public static void Main(string[] args)
{
CreateWebHostBuilder(args).UseDefaultServiceProvider(options =>
options.ValidateScopes = false).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
Startup.cs 的部分内容
// For those 2 Views that are coming from another assembly (this 2 views are present in the Views folder of publish directory)
var myAssembly = typeof(Component).Assembly;
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddApplicationPart(myAssembly);
services.Configure<RazorViewEngineOptions>(options =>
{
options.FileProviders.Add(new EmbeddedFileProvider(myAssembly, "MyNS"));
});
//For serving static files from folder call Contents, outside of wwwroot
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(_env.ContentRootPath, "Contents")),
RequestPath = "/Contents"
});
.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<UserSecretsId>........</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Tools" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0-preview3-35497">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0-preview3-35497" />
<PackageReference Include="morelinq" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Proj.Business\Proj.Business.csproj" />
<ProjectReference Include="..\Proj.Common\Proj.Common.csproj" />
<ProjectReference Include="..\Proj.Data\Proj.Data.csproj" />
<ProjectReference Include="..\MyNS\MyNS.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Contents\" CopyToPublishDirectory="PreserveNewest" />
<Folder Include="PrivateContents\" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
</Project>
当我将应用发布到 Azure 应用服务时,我得到了相同的结果,我的应用出了什么问题?部署 asp.net core 2.1 应用程序后还有什么需要注意的吗?请帮忙。
解决方案
只是改变
<Folder Include="Contents\" CopyToPublishDirectory="PreserveNewest" />
<Folder Include="PrivateContents\" CopyToPublishDirectory="PreserveNewest" />
至
<Content Include="Contents\**\*" CopyToPublishDirectory="PreserveNewest" />
<Content Include="PrivateContents\**\*" CopyToPublishDirectory="PreserveNewest" />
推荐阅读
- terraform - Remote-exec 无法在具有 aws_instance 资源的 Terraform 中工作
- javascript - 是否可以向 CORS 预检请求添加请求标头?
- javascript - 尝试使用 JQuery 单击链接,但标签没有任何描述符
- groovy - 如何使用 Groovy sql 模块定义数据库“驱动程序”
- python - 安装 pyflann 后没有名为“index”的模块
- owl - CWA 和 OWA 在语义 Web 应用程序中的作用是什么?
- actionscript-3 - 无法访问影片剪辑中的文本字段
- java - 以字符串开头的 Java Servlet 模式
- oracle - ORACLE:在同一条语句中分配和检查
- java - 在Java中将元素插入到多个数组类中