I'm using MSDeploy.exe to publish my webapp:
msdeploy.exe
-verb:sync
-source:package=mypackage.zip
-dest:auto,computerName=MyServer
-allowUntrusted
This will sync my package to destination server and delete all the unneeded files during the process. Sometimes resources (eg: MyResource.dll) are locked by IIS worker process and it wouldn't allow the delete operation, thus deployment failed with error:
Access to the path "C:\MyResource.dll" is denied.
However, if I use the Publish feature from within VisualStudio, my website gets published to the server without any problem. The locked files remained in the folder and the error is simply ignored.
I figured VS probably uses this switch:
-enableRule:DoNotDeleteRule
But I'm not very sure about that.
My questions:-
I've also tried PSEXEC:
psexec.exe -s \\MyServer appcmd.exe stop apppool /apppool.name=MyAppPool
It runs fine in command line, but when I put it in script for build-automation, it returned error:
The handle is invalid.
Couldn't access MyServer.
(banging my head against the wall)
Basic command-line publishing The default publish folder format is bin\Debug\{TARGET FRAMEWORK MONIKER}\publish\. For example, bin\Debug\netcoreapp2. 2\publish\. The dotnet publish command calls MSBuild, which invokes the Publish target.
Publish profile files are named <profilename>. pubxml and are located in the PublishProfiles folder. The PublishProfiles folder is under Properties in a C# web application project, under My Project in a VB web application project, or under App_Data in a web site project.
How does Publish in Visual Studio Work? In simple terms, Publishing creates the set of files that are needed to run your application, and you can deploy the files by copying them to a target machine.
To answer my own questions:
1) Can we get the publish command used by VS through output window or log files?
Yes, we can output the command to output window.
All you need to do is simply add a file named <YourProjectName>.wpp.targets
to the root of your project directory. And edit the contents as below:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseMsdeployExe>true</UseMsdeployExe>
</PropertyGroup>
</Project>
Now you can Publish using Visual Studio and the MSDeploy command can be seen in the output window.
Checkout Sayed Ibrahim Hashimi blog here for more info.
2) Is there a way to stop application pool on a remote server?
I managed to start/stop/recycle remote AppPool using -preSync -postSync of MSDeploy command.
MSDeploy.exe
-source:package="mypackage.zip"
-dest:auto,ComputerName=MyServer,IncludeAcls=False
-verb:sync
-disableLink:AppPoolExtension
-disableLink:ContentExtension
-disableLink:CertificateExtension
-allowUntrusted
-preSync:runCommand="C:\Windows\System32\inetsrv\appcmd stop apppool <AppPoolName>"
-postSync:runCommand="C:\Windows\System32\inetsrv\appcmd start apppool <AppPoolName>"
Hope this helps =)
2) Use appoffline rule to stop your application during deployment:
msdeploy.exe -verb:sync -source:package=mypackage.zip -dest:auto,computername=<publishUrl> -enableRule:AppOffline
This will put app_offline.htm into your web app root dir for the tie of the sync operation (which forces IIS to unload the application and only serve this static file to all requests untill the file is deleted - here is a good explanation http://weblogs.asp.net/scottgu/426755)
see http://www.iis.net/learn/publish/deploying-application-packages/taking-an-application-offline-before-publishing and for details. You can use a more flexible approach, if you need (e.g. use separate webdeploy command to copy app_offline.htm before running the sync for a package).
1) Have you tried setting msbuild verbosity to diagnostic?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With