问题
Using Visual Studio 2019 Community 16.3.6
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
All of the required files are copied, EXCEPT for the "www" folder and any files within it.
Hence, when I run the project, I get 404 errors because the static files were NOT copied during the publish operation.
WHY????
Any advice would be appreciated.
回答1:
Poking around in the documentation at:
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-3.0#folder-publish-example
I found this little tidbit:
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\**
Since I used "www" instead of "wwwroot", I suspect the "www" folder (and anything within) will NOT be copied.
SOLUTION:
1 - In Visual Studio, right-click on the project name, then click on "Edit Project File"
2 - Include the following entry in the {project-name}.csproj file:
<ItemGroup>
<Include="www\**" CopyToPublishDirectory="Always"/>
</ItemGroup>
3 - Save the file.
When you setup a Publish profile, the "www" folder and anything beneath will be included.
来源:https://stackoverflow.com/questions/58551129/visual-studio-2019-publish-to-a-folder-does-not-publish-all-files