Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we get the same publish command used in VisualStudio Publish

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:-

  1. Can we get the publish command used by VS through output window or log files?
  2. Is there a way to stop application pool on a remote server? (this will help release the locked resources) *IISRESET is not suitable because I don't want to bring down all websites just to deploy one webapp.

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)

like image 706
Kagawa Avatar asked Jul 18 '14 16:07

Kagawa


People also ask

What command does Visual Studio use to publish?

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.

Where can I find publish profile?

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 Visual Studio publish work?

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.


2 Answers

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 =)

like image 166
Kagawa Avatar answered Sep 21 '22 04:09

Kagawa


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?

like image 27
Isantipov Avatar answered Sep 20 '22 04:09

Isantipov