在 wwwroot 下部署自定义静态文件夹

Deploying a custom static folder under wwwroot

我们在 wwwroot 下有一个名为 Contents 的自定义文件夹,其中一些内部文件夹构成了用于组织以后可上传文件的结构,在发布未部署的模式(在本地或服务器上)

以下是您可能感兴趣的部分代码:

app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(
        Path.Combine(Directory.GetCurrentDirectory(), "Contents")),
    RequestPath = "/Contents"
});

有什么建议和解决办法吗?知道为什么它没有部署吗?

更新:

在 .csProj 中我们有这个:

  <ItemGroup>
    <Folder Include="Contents\H2X\" />
    <Folder Include="ServerContent\H123\" />
  </ItemGroup>  

我们有 H2X.publishSettings 个文件, 它由服务器生成并包含我们的一些凭据。

   msdeploySite="213" 
   destinationAppUrl="123" 
   profileName="Default Settings" 
   publishMethod="MSDeploy" userName="123" 
   AllowUntrustedCertificate="True"

有什么遗漏吗?

有一段时间我有点远离开发,现在我的开发人员似乎陷入困境,想帮助他。

在 ASP.NET 核心托管环境中,有两个属性经常用于构建文件或目录的物理路径。

_hostingEnvironment.WebRootPath 直接映射到默认的 wwwroot 目录:

_hostingEnvironment.ContentRootPath 映射更高一级,通常是 startup.cs 文件所在的位置。

要将文件直接上传到位于 wwwroot 文件夹内的文件夹,请使用 WebRootPath 构建您需要的路径。

如果Contents文件夹里面有wwwroot然后添加

<Content Include="wwwroot\**\*" CopyToPublishDirectory="PreserveNewest" />

并且您无需在 Startup.cs 中将 Contents 文件夹配置为静态文件提供程序,上面的行将包括所有wwwroot.

中的子文件夹和文件

如果 Contents 文件夹位于 wwwroot 之外,则添加

<Content Include="Contents\**\*" CopyToPublishDirectory="PreserveNewest" />

并且您需要在 Startup.cs

中将 Contents 文件夹配置为静态文件提供程序