I am trying to Publish a sample DotNetCore project (from the basic VueJs/Core solution template) to an IIS server with the ‘Delete Existing Files’ option. If the app has been running, then the Publish throws errors because of files that it cannot delete. Fortunately, a second Publish succeeds as the first attempt shuts the app down and allows the files to be deleted.
<Target Name="AddAppOffline" BeforeTargets="Publish">
<Message Text="Copying app_offline.htm" Importance="high" />
<Copy SourceFiles="app_offline.htm" DestinationFolder="$(PublishDir)" />
<Message Text="Completed Copying app_offline.htm" Importance="high" />
</Target>
<Target Name="RemoveAppOffline" AfterTargets="Publish">
<Message Text="Deleting app_offline.htm" Importance="high" />
<Delete Files="$(PublishDir)app_offline.htm" />
</Target>
I am using the code above in the .csproj file that should add the app_offline.htm file into Publish folder to shut the app pool down. Despite the order shown in the VS Output window, I do not see the file being added before the Delete errors are thrown.
Build started at 1:18 AM...
1>------ Build started: Project: vuecore2024.client, Configuration: Release Any CPU ------
2>------ Build started: Project: VueCore2024.Server, Configuration: Release Any CPU ------
2>VueCore2024.Server ->
C:GitSamples2024VueCore2024VueCore2024.Server
binReleasenet8.0VueCore2024.Server.dll
3>------ Publish started: Project: VueCore2024.Server, Configuration: Release Any CPU ------
Connecting to C:tempVueCore2024...
VueCore2024.Server -> C:GitSamples2024VueCore2024VueCore2024.Server
binReleasenet8.0VueCore2024.Server.dll
npm run build
> [email protected] build
> vite build
[36mvite v5.2.11 [32mbuilding for production...[36m[39m
transforming...
[32mΓ£ô[39m 23 modules transformed.
rendering chunks...
computing gzip size...
[2mdist/[22m[32mindex.html
[39m[1m[2m 0.43 kB[22m[1m[22m[2m Γöé gzip: 0.29 kB[22m
[2mdist/[22m[35massets/index-BXAxuANx.css
[39m[1m[2m 3.73 kB[22m[1m[22m[2m Γöé gzip: 1.22 kB[22m
[2mdist/[22m[36massets/index-X070Lzgl.js
[39m[1m[2m64.83 kB[22m[1m[22m[2m Γöé gzip: 25.70 kB[22m
[32mΓ£ô built in 547ms[39m
Copying app_offline.htm
Completed Copying app_offline.htm
VueCore2024.Server -> C:GitSamples2024VueCore2024VueCore2024.Server
objReleasenet8.0PubTmpOut
C:Program Filesdotnetsdk8.0.204SdksMicrosoft.NET.Sdk.Publish
targetsPublishTargetsMicrosoft.NET.Sdk.Publish.FileSystem.targets(63,5):
Error MSB3061: Unable to delete file
"C:tempVueCore2024Microsoft.AspNetCore.OpenApi.dll". Access to the path
'C:tempVueCore2024Microsoft.AspNetCore.OpenApi.dll' is denied.
C:Program Filesdotnetsdk8.0.204SdksMicrosoft.NET.Sdk.Publish
targetsPublishTargetsMicrosoft.NET.Sdk.Publish.FileSystem.targets(63,5):
Error MSB3061: Unable to delete file
"C:tempVueCore2024Microsoft.OpenApi.dll".
Access to the path 'C:tempVueCore2024Microsoft.OpenApi.dll' is denied.
C:Program Filesdotnetsdk8.0.204SdksMicrosoft.NET.Sdk.Publish
targetsPublishTargetsMicrosoft.NET.Sdk.Publish.FileSystem.targets(63,5):
Error MSB3061: Unable to delete file
"C:tempVueCore2024Swashbuckle.AspNetCore.Swagger.dll". Access to the path
'C:tempVueCore2024Swashbuckle.AspNetCore.Swagger.dll' is denied.
C:Program Filesdotnetsdk8.0.204SdksMicrosoft.NET.Sdk.Publish
targetsPublishTargetsMicrosoft.NET.Sdk.Publish.FileSystem.targets(63,5):
Error MSB3061: Unable to delete file
"C:tempVueCore2024Swashbuckle.AspNetCore.SwaggerGen.dll". Access to the path
'C:tempVueCore2024Swashbuckle.AspNetCore.SwaggerGen.dll' is denied.
C:Program Filesdotnetsdk8.0.204SdksMicrosoft.NET.Sdk.Publish
targetsPublishTargetsMicrosoft.NET.Sdk.Publish.FileSystem.targets(63,5):
Error MSB3061: Unable to delete file
"C:tempVueCore2024Swashbuckle.AspNetCore.SwaggerUI.dll". Access to the path
'C:tempVueCore2024Swashbuckle.AspNetCore.SwaggerUI.dll' is denied.
C:Program Filesdotnetsdk8.0.204SdksMicrosoft.NET.Sdk.Publish
targetsPublishTargetsMicrosoft.NET.Sdk.Publish.FileSystem.targets(63,5):
Error MSB3061: Unable to delete file "C:tempVueCore2024VueCore2024.Server.dll".
Access to the path 'C:tempVueCore2024VueCore2024.Server.dll' is denied.
3>Build failed. Check the Output window for more details.
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 1:18 AM and took 03.698 seconds ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
========== Publish completed at 1:18 AM and took 03.698 seconds ==========
The path to the app_offline.htm file is working correctly as the file is there at the end of the publish if the Delete Target step is removed. My guess is that the timing is somehow off with the deletions happening before the App Pool shutdown is complete.
Any suggestion as to how to make this work on the first publish, preferably without having to resort to a external Powerscript file or something more elaborate?