Files and folders generated during publish aren't copied from wwwroot to output
See original GitHub issueSteps to reproduce
See sample project for reproduction here https://github.com/damienpontifex/NotPublishingGeneratedFiles
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
<Exec Command="npm install" />
<Exec Command="npm run build" />
</Target>
npm build script
"scripts": {
"build": "tsc"
}
tsconfig.json has the property outFile = wwwroot/ts/app.js
PrepareForPublish compiles typescript into wwwroot/ts folder.
This folder is also removed on dotnet clean
and ignored by git
Steps to reproduce:
dotnet restore
dotnet publish -c Release -o <your output dir>
If you re-run the publish step, the files are appropriately copied as they existed at the time the publish was started.
If you run dotnet clean
to clear away generated files and re-run publish step, they are again missed when copying to output as per original restore and publish.
I have also tried changing the PrepublishScript target value of BeforeTargets to ComputeFilesToPublish from looking at targets here https://github.com/dotnet/sdk/blob/master/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Publish.targets but with no success
n.b. If I generate the files into a folder that does exist and has content (e.g. wwwroot/js has site.js in it) then the copy works fine. It’s only if I generate both a new folder and the files inside it in this step
Expected behavior
Files generated into wwwroot to be in output directory under wwwroot
Actual behavior
Files are generated in source wwwroot folder, but not copied into publish output wwwroot folder
Environment data
dotnet --info
output:
.NET Command Line Tools (1.0.0-rc3-004530)
Product Information: Version: 1.0.0-rc3-004530 Commit SHA-1 hash: 0de3338607
Runtime Environment: OS Name: Mac OS X OS Version: 10.12 OS Platform: Darwin RID: osx.10.12-x64 Base Path: /usr/local/share/dotnet/sdk/1.0.0-rc3-004530
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:23 (12 by maintainers)
Top GitHub Comments
@dsplaisted thank you for suggesting this workaround! Unfortunately I found it to kick in during every build in Visual Studio, which would slow down development significantly.
My use case is a Webpack task that should run after the C# Web project is compiled, but only before it’s published; the publish output should pick up the files generated by the Webpack task in
wwwroot/dist
.I cobbled together something to unblock myself for now, through a painful half-day of running
dotnet publish
with diagnostic verbosity to figure this out. This feels fragile and I’m sure a future update would break it. I am hoping for a better solution and thus 👍 to adding something supported to the Web SDK.Here is the task I used in case someone else finds it useful:
Yes, the content items from wwwroot are calculated during evaluation before any targets are run.
@damienpontifex @nil4 @armartinez As a workaround, you can add this target to your project file:
@mlorbetske @vijayrkn Should we consider adding something like this to the Web SDK so that files added to wwwroot by npm tasks or similar get included in the publish output?