Visual Studio 2019 - 发布到文件夹不会发布所有文件 [英] Visual studio 2019 - Publish to a folder does not publish all files

查看:65
本文介绍了Visual Studio 2019 - 发布到文件夹不会发布所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Visual Studio 2019 社区 16.3.6

Using Visual Studio 2019 Community 16.3.6

我有一个简单的 ASP.Net core 3.0 网站项目(此时大部分为空),但我确实在该文件夹中添加了一个 web 根文件夹 (www) 和一个静态 index.html 文件,如下所示:

I have a simple ASP.Net core 3.0 website project (mostly empty at this point), but I did add a web root folder (www) and a static index.html file within that folder, as shown below:

website0
 > www
   - index.html
 > Program.cs
 > Startup.cs

例如,当我尝试在本地发布到文件夹(作为测试)时,我将目标指定为:

When I try to publish to a folder locally (as a test), for example, I specify the destination as:

D:\ws0

复制所有必需的文件,www"文件夹及其中的任何文件除外.

All of the required files are copied, EXCEPT for the "www" folder and any files within it.

因此,当我运行项目时,我收到 404 错误,因为在发布操作期间未复制静态文件.

Hence, when I run the project, I get 404 errors because the static files were NOT copied during the publish operation.

为什么????

任何建议将不胜感激.

推荐答案

浏览文档:

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-3.0#folder-publish-例子

我发现了这个小花絮:

发布 ASP.NET Core Web 应用程序时,以下资产是包括:

When publishing ASP.NET Core web apps, the following assets are included:

- Build artifacts
- Folders and files matching the following globbing patterns:
  **\*.config (for example, web.config)
  **\*.json (for example, appsettings.json) wwwroot\**

由于我使用了www"而不是wwwroot",我怀疑www"文件夹(以及其中的任何内容)不会被复制.

Since I used "www" instead of "wwwroot", I suspect the "www" folder (and anything within) will NOT be copied.

解决方案:

1 - 在 Visual Studio 中,右键单击项目名称,然后单击编辑项目文件"

1 - In Visual Studio, right-click on the project name, then click on "Edit Project File"

2 - 在 {project-name}.csproj 文件中包含以下条目:

2 - Include the following entry in the {project-name}.csproj file:

<ItemGroup>
   <Include="www\**" CopyToPublishDirectory="Always"/>
</ItemGroup>

3 - 保存文件.

当您设置发布配置文件时,www"文件夹和下面的任何内容都将包含在内.

When you setup a Publish profile, the "www" folder and anything beneath will be included.

这篇关于Visual Studio 2019 - 发布到文件夹不会发布所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆