publish command not copying wwwroot files on first run
Steps to reproduce
- Clone project from github repo: https://github.com/ckuyehar/dotnet-mvc-bug
dotnet restoredotnet publish
Expected behavior
The first time I run dotnet publish, I expected the assets folder to be copied to the published wwwroot folder.
Actual behavior
The first time I run dotnet publish, the published wwwroot folder (ie, bin\Debug\netcoreapp1.1\publish\wwwroot) is missing the assets folder .
After running dotnet publish for the first time, if you make changes to the file a.txt contained in the .\assets folder and run dotnet publish again the published wwwroot folder will always contain the latest changes made to the file a.txt.
Environment data
dotnet --info output:
.NET Command Line Tools (1.0.3)
Product Information: Version: 1.0.3 Commit SHA-1 hash: 37224c9917
Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\1.0.3
I was just informed that this was caused by my incorrect understanding of msbuild.
You may close.
What was your misunderstanding? It may be valuable to other people who come across a similar issue.
@ckuyehar I'm having a similar issue - what was your misunderstanding?
I misunderstood how msbuild works. I assumed msbuild would understand what files to include after a
So say you clone the repo I mentioned above and then performed a dotnet restore. When you execute dotnet publish it performs a build and then a publish. When the publish target runs somewhere in the pipeline it calls another target called _CopyResolvedFilesToPublishPreserveNewest. That target doesn't know about the new file (in wwwroot) so as a result it doesn't copy it over to the publish folder.
So the solution? dotnet build and then dotnet publish.
Looks like a duplicate of https://github.com/aspnet/websdk/issues/114
There is a fix in the web sdk now that re-scans the glob patterns before publish but i don't know if this is going to be included in 1.1 or 2.0 CLIs..
Thank you both!
For the time being, I've implemented a workaround documented here https://github.com/dotnet/cli/issues/5498#issuecomment-275932671.
Who still has similar issue try to read my comment