Publishing .Net Core app to IIS fails if Visual Studio 2017 when "Delete Existing Files" option is selected - iis

When trying to publish my .Net Core app to a remote IIS server I am unable to publish with the "Delete Existing Files" option selected. When I try I get hundreds of errors for each file saying: Unable to remove ... The process cannot access the file ... because it is being used by another process.
If I shut down the kestrel server or put app_offline.htm in the web folder I still get an error for the root folder of the web app: Unable to remove directory "\remoteserver\webapp\". The process cannot access the file "\remoteserver\wenapp\' because it is being used by another process.
I literally have to shut down IIS to publish which is not ideal. Any suggestions? I have made sure the permissions allow read an write to users.

Related

How to stop running multiple application insights for Azure Web App?

We have enabled Application Insights for an Azure Web App. The following highlighted Application Insights automatically added to the app service even after deleted manually. Is there anyway to permanently disable/delete this?
NOTE: We have configured Scale Out (Max: 10 instances) for the App Service.
It seems that the old extension was not properly removed when you enabled the new experience. Even though the App Service doesn't show the "Microsoft.ApplicationInsights.AzureWebSites" extension as being installed, the extension is still there and periodically writes ApplicationInsightsProfiler2.
To solve the problem open Kudu and remove this entire folder: "D:\home\SiteExtensions\Microsoft.ApplicationInsights.AzureWebSites".
You might get an access denied (some of the files might be loaded in the running process). If that happens you have 2 options:
Stop the App Service and try removing the folder again.
Only remove "D:\home\SiteExtensions\Microsoft.ApplicationInsights.AzureWebSites\applicationHost.xdt" & "D:\home\SiteExtensions\Microsoft.ApplicationInsights.AzureWebSites\scmApplicationHost.xdt" and then restart the AppService. Now the extension is not used anymore and you can safely remove the entire folder.
Open Kudu in your web app and browse till wwwroot
and then browse to Continuous folder under Jobs - D:\home\site\wwwroot\App_Data\jobs\continuous>
Check if you see any folder name ApplicationInsightsProfiler2. If yes then delete it.
It worked for me.
Open Kudu Console:
https://YOURWEBAPP.scm.azurewebsites.net/DebugConsole
To remove the WebJob from the Kudu dashboard:
rmdir /s /q D:\home\site\wwwroot\App_Data\jobs\continuous\ApplicationInsightsProfiler2
Remove the old applicationinsights folder:
rmdir /s /q D:\home\SiteExtensions\Microsoft.ApplicationInsights.AzureWebSites
Any locked files can be removed manually one by one without needing to stop the WebApp service.

Azure - Web deployment task failed. An error was encountered when processing operation 'Delete Directory' on (Application Insights)

I'm using Right-Click publish in Visual Studio to publish directly to my staging slot in Azure. I've added Application Insights that added a WebJob to my app.
I have enabled Remove additional files at destination and Precompile during Publishing turned on.
But when a Web Job is running and my staging site is not 'stopped', because it's still warmed up - I get the following error:
Web deployment task failed. ((18-Jan-18 22:47:23) An error occurred
when the request was processed on the remote computer.)
(18-Jan-18 22:47:23) An error occurred when the request was processed
on the remote computer. An error was encountered when processing
operation 'Delete Directory' on
'D:\home\site\wwwroot\App_Data\jobs\continuous'. The error code was
0x80070091. The directory is not empty.
at
Microsoft.Web.Deployment.NativeMethods.RaiseIOExceptionFromErrorCode(Win32ErrorCode
errorCode, String maybeFullPath) at
Microsoft.Web.Deployment.DirectoryEx.Delete(String path) at
Microsoft.Web.Deployment.DirPathProviderBase.Delete(Boolean
whatIf) ProjectX.Web 7 0
I can fix this by manually stopping the staging slot, upload it, and then start it again. This is quite cumbersome though.
Is there a fix?
I read somewhere that you can automatically take the (staging) app offline during publish but I can't find the setting.
UPDATE 1
<PropertyGroup>
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
</PropertyGroup>
...is not working for me.
UPDATE 2
Adding the WEBJOBS_STOPPED setting on the Staging slot is not working for me.
As you have enabled Application Insights on your Azure App Service, it has internally installed an extension which started a continuous web job and content corresponding to web job got copied to App_Data folder. The actual problem is because extension data get copied to App_Data folder where only user's data should reside instead of infrastructure data.
Now when you are selecting the option "Remove Additional Files From Destination" in visual studio, it tries to remove all contents including Application Insights data from App_Data folder. Since Application Insights web job is already running in background hence corresponding dll files are locked.
Even if you go with option of "App Offline" or "Stop web job" and successfully able to delete all contents then your deployment will succeed but this way your Application Insights will get corrupted and hence you may have to configure Application Insights again.
Suggestion:
Select skip "App_Data" folder along with option "Remove Additional Files From Destination".
It will delete all content except App_Data folder content and hence dll files corresponding to Application Insights continuous web job will be skipped.
Reference :
VSTS - Azure App Service Task Documentation
Limitation
Though this solution have a limitation - If you want to remove/modify existing user defined web jobs then can't skip App_Data folder. In such case either have to perform two step deployment or have to reinstall application insight extension again.
I found this in another SO question:
<PropertyGroup>
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
...
</PropertyGroup>
... adding to your publishing profile (.pubxml).
The full answer is here: https://stackoverflow.com/a/20888597/647845
UPDATE
This is not working for me. Maybe for others. Seems to ignore the setting.

Azure WebJob deployment keeps failing

Since yesterday I'm suddenly having consistent deployment failures for my existing WebJobs. The error I'm getting is
Start Web Deploy Publish the Application/package to https://octotrip-api-test-dev.scm.azurewebsites.net/msdeploy.axd?site=octotrip-api-test__dev ...
Adding sitemanifest (sitemanifest).
Adding directory (XXX\app_data).
Adding directory (XXX\app_data\jobs).
Adding directory (XXX\app_data\jobs\continuous).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets(4295,5): Error : Web deployment task failed. ((3/16/2017 1:32:23 PM) An error occurred when the request was processed on the remote computer.)
(3/16/2017 1:32:23 PM) An error occurred when the request was processed on the remote computer.
An error was encountered when processing operation 'Create Directory' on 'D:\home\site\wwwroot\app_data\jobs\continuous'.
The error code was 0x800700B7.
Cannot create "D:\home\site\wwwroot\app_data\jobs\continuous" because a file or directory with the same name already exists.
at Microsoft.Web.Deployment.NativeMethods.RaiseIOExceptionFromErrorCode(Win32ErrorCode errorCode, String maybeFullPath)
at Microsoft.Web.Deployment.DirectoryEx.CreateDirectory(String path)
at Microsoft.Web.Deployment.DirPathProviderBase.CreateDirectory(String fullPath, DeploymentObject source)
at Microsoft.Web.Deployment.DirPathProviderBase.Add(DeploymentObject source, Boolean whatIf)
Publish failed to deploy.
Important to note that at the time of the deployment; there is no app_data folder (I removed it manually using FTP). You can see it is creating the folder structure step by step; app_data, then the jobs folder, then the continuous folder. I confirmed using FTP that he succesfully creates the app_data/jobs folder; but creating the continuous folder consistently crashes.
This happens when deploying using a build definition in VSTS as well as deploying as a WebJob from within Visual Studio; with all the WebJob NuGet up to date.
Thanks
It is very odd that can't create folder for WebJob. I can't repro it in my side. Do you have a try to deploy it to another website to check whether it can be repro?
Based on my experience, we could troubleshoot with following ways:
Restart the Website
If it is possible try to redeploy the Website and remove additional files at destination
Scale up and scale down back Service plan
Note:change will be applied to all WebApps in the ServicePlan
Please contact Azure Support team for help if it is not resolved .
Worked around the issue by simply creating a new Azure Web App. Something messed up going on with the file system. Take a look.
app_data or subdirectories of app_data don't exist on the server. (confirmed using CMD and FTP).
This only happens for
app_data\jobs\triggered and
app_data\jobs\continuous
(app_data\jobs\triggereddddd works for example)
These folders have existed on this server before (they contain the data for the WebJobs that we're running)
open Azure Portal and go to your web app
Under "development tools" select "K Advanced Tools" this will open the Kudu control panel in a new browser window.
Select "Debug Console" -> "CMD"
in the Items table, locate the wwwroot entry and delete it.
continue working ...

How to restart a dnx website in production?

I updated a ASP.NET CORE/ASP.NET 5 RC1 controller cs file with a programming change.
The site has previously been deployed on production on IIS7.5 Windows 2012 Server which makes use of HTTPPlatformHandler installed in IIS.
This is a remote server I have to access via VPN.
The site is setup as an application in IIS and the folder points to the wwwroot directory of the deployed site.
I deploy it currently by deploying it first locally by right clicking on my project in Visual Studio 2015 and selecting publish to local folder. I then copy the contents of the local folder to the remote network IIS7.5 web server site folder.
If I copy for example the appsettings.json or a changed .cs file to the server, the change will not reflect.
If I copy the whole site to the production server I get folders and files in use messages. I have to kill the 'dnx' process in order to copy without getting these messages.
From my understanding if I kill the process dnx it will force a recompile. This is currently the only way I know of to restart the site after updating it but I imagine it is not the best way.
What is the standard practice to restart your website after you update your production sites that run ASP.NET5 RC1?
Also changing my app.settings json file aslo doesn't trigger a site reload like changing the web.config did in ASP.NET 4 so being able to restart a site is important.
If I have multiple sites on the same app pool and I only want to update one in production. How can I only restart the one site to reflect the latest changes?
Is it possibly to restart the website to reflect the change as updating it directly doesn't cause a recompile taking into consideration if I only have access to a shared folder and not the web server itself?
With IISPlatformHandler, DNX process is started by IIS (instructions are in wwwroot\web.config).
IIS knows nothing about your source files, all requests are forwarded to DNX.
DNX does NOT watch source files for changes, because there is no dnx-watch there.
IIS only watches for wwwroot\web.config file changes, so you need to change/edit/touch it to force IIS to restart website (and DNX process).
I use msdeploy to deploy, it has commands to stop and start app pools, using these commands has resolved my file in use errors. There are lots of ways to use msdeploy, below is how I happen to be using it.
msdeploy -verb:sync -source:recycleApp -dest:recycleApp="site/pool",recycleMode="StopAppPool",computername=COMPUTERNAME
msdeploy -source:contentPath='SOURCE PATH' -dest:contentPath='\\COMPUTERNAME\wwwroot\' -verb:sync -retryAttempts:2 -disablerule:BackupRule
msdeploy -verb:sync -source:recycleApp -dest:recycleApp="site/pool",recycleMode="StartAppPool",computername=COMPUTERNAME

Why is Visual Studio failing to copy a dll to my web directory (IIS file locking issue)?

What is causing these frustrating errors during every Visual Studio build operation?
Could not copy "obj\Debug\mywebapp.dll" to "bin\mywebapp.dll".
Exceeded retry count of 10. Failed. Unable to copy file
"obj\Debug\mywebapp.dll" to "bin\mywebapp.dll". The process cannot
access the file 'bin\mywebapp.dll' because it is being used by another
process.
I'm fairly certain that w3wp.exe is locking the file, because the error stops if I restart or shut down IIS from IIS manager. ProcessExplorer shows that w3wp and visual studio are the only processes with locks on the file. Obviously IIS is the issue, because the compilation succeeds when IIS is restarted.
I am using dynamic assemblies loaded into a child application domain. Could those be referencing the file? I tried added an event handler to the Global.asax application_end event to ensure the child app domain is unloaded, but the handler never runs. Also, the debugger's "modules" window shows various modules, but the AppDomain field is always blank, so I cannot even determine if that might be an issue.
Make sure that you've set up your web application within Visual Studio to use Local IIS for debugging:
I kept getting the exact same error. I deleted my old Web Application/Web Site from IIS and created a brand new one with a different name (not sure if you have to have a different name but that worked for me). Now it all works great!

Resources