How can I use the "wmsvc=[server]" syntax with the dirPath provider? - msdeploy

I'm trying to deploy a Windows application to a specific path on my remote server, using the dirPath provider. I'm able to deploy websites with no issue to this same server, using a syntax like the following:
msdeploy.exe -verb:sync -source=iisApp=C:\SomePath -dest:authType=basic,wmsvc=MyServer,userName=MyUser,password=MyPassword,iis=MySite/MyApp -allowUntrusted
However, I get 401 Unauthorized errors (for unknown reasons) when attempting a similar command using dirPath:
msdeploy.exe -verb:sync -source=dirPath=C:\SomePath -dest:authType=basic,wmsvc=MyServer,userName=MyUser,password=MyPassword,dirPath=C:\SomeRemotePath -allowUntrusted
The only thing I've found to work here is to switch to using the computerName syntax, like this:
msdeploy.exe -verb:sync -source=dirPath=C:\SomePath -dest:authType=basic,computerName=https://MyServer:8172/msdeploy.axd?site=MySite,userName=MyUser,password=MyPassword,dirPath=C:\SomeRemotePath -allowUntrusted
This would be fine, but computerName requires the site be passed as a query string parameter, and "MySite" in this case is actually "Default Web Site". I cannot for the life of me figure out how to escape the spaces here properly, given that I'm actually generating this command line with an MSBuild file (and executing it with an Exec statement). If I specify %20 in the MSBuild file (e.g., Default%20Web%20Site), it resolves it back to a space before executing the command, which results in an invalid syntax. If I try a double escape (escaping %, 2, and 0 separately, e.g., Default%25%32%30Web%25%32%30Site), I go back to 401 Unauthorized errors.
So, is there some syntax or server configuration that would allow me to use "wmsvc=[server]" in this command, given that it does not require the problematic (inescapable?) site query parameter? Or can someone tell me how to escape "?site=Default Web Site" properly within an MSBuild Exec command that is executing the MSDeploy command above?
EDIT: Before someone suggests that I just rename Default Web Site to something without spaces, yes, that works, but I'm trying to find a way to avoid that, as I'd like a generic solution that can work with the default name of the IIS website on any given server.

The proper approach to escaping the site parameter (when using the computerName syntax) comes from another SO post regarding use of curl, which is to escape the % sign by doubling it, e.g., Default%25%2520Web%25%2520Site. If there isn't a way to use wmsvc and thus not specify the site at all, this will work for me.
EDIT: As just pointed out by The Muffin Man, simply putting quotes around the entire computerName argument (including the Site query parameter) avoids the need to do any tricky escaping of the site name.

Related

Is it possible to publish/deploy a web package, using a non-admin account, from the command line only?

The title needs some expansion. In summary, I am finding it impossible to:
Deploy a web site to an IIS 8 host
Using a Web Deploy Package
Using the out-of-the-box publish functionality in VS 2013
Using a non-admin IIS Manager User, which is delegated permission to deploy to the given site
It all seems to come down to one small detail that messes it all up, but I should describe my process up to the point where it all falls apart.
I create a publish profile Publish in VS 2013, configured to publish to a web package. I then fire the following command at a developer command prompt:
msbuild Solution.sln /t:Build /p:DeployOnBuild=true;PublishProfile=Publish;IsDesktopBuild=false
This goes through a build process and I now see the expected package and deployment files in the _PublishedWebsites\Web_Package folder. My next step is run this from the Web_Package folder:
Web.deploy.cmd /Y /M:https://example.blah:8172/MsDeploy.axd /U:user /P:p#44w0rd /A:Basic
This is where the problem comes in. This results in the following expanded command (formatted for ease of reading):
msdeploy.exe
-source:package='.\Web.zip'
-dest:auto,computerName="https://example.blah:8172/MsDeploy.axd",userName="user",password="p#44w0rd",authtype="Basic",includeAcls="False"
-verb:sync
-disableLink:AppPoolExtension
-disableLink:ContentExtension
-disableLink:CertificateExtension
-setParamFile:".\Web.SetParameters.xml"
whose execution results in:
Error Code: ERROR_USER_UNAUTHORIZED
More Information: Connected to the remote computer ("example.blah") using the Web Management Service, but could not authorize. Make sure that you are using the correct user name and password, that the site you are connecting to exists, and that the credentials represent a user who has permissions to access the site. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.
I can fix this problem by manually re-running just the expanded command and tagging on the site parameter to the MsDeploy.axd URL, like so:
msdeploy.exe
-source:package='.\Web.zip'
-dest:auto,computerName="https://example.blah:8172/MsDeploy.axd?site=example.blah",userName="user",password="p#44w0rd",authtype="Basic",includeAcls="False"
-verb:sync
-disableLink:AppPoolExtension
-disableLink:ContentExtension
-disableLink:CertificateExtension
-setParamFile:".\Web.SetParameters.xml"
However, I cannot see any way to have this set through Web.deploy.cmd which was auto-generated by MSBuild. If I try this:
Web.deploy.cmd /Y /M:https://example.blah:8172/MsDeploy.axd?site=example.blah /U:user /P:p#44w0rd /A:Basic
It results in this (again, formatted for ease of reading):
msdeploy.exe
-source:package='D:\DEV\Solution\Web\bin\_PublishedWebsites\Web_Package\Web.zip'
-dest:auto,computerName="https://example.blah:8172/MsDeploy.axd?site",userName="user",password="p#44w0rd",authtype="Basic",includeAcls="False"
-verb:sync
-disableLink:AppPoolExtension
-disableLink:ContentExtension
-disableLink:CertificateExtension
-setParamFile:"D:\DEV\Solution\Web\bin\_PublishedWebsites\Web_Package\Web.SetParameters.xml" example.blah
Error: Unrecognized argument 'example.blah'. All arguments must begin with "-".
Error count: 1.
I can perform this process fine using an admin account. But it seems that the non-admin requires this site= querystring value and the auto-generated Web.deploy.cmd just isn't having any of that.
Am I missing something obvious here? Is there a permission I'm missing on the IIS Management side? I've made sure I have the Management Service Delegation rule set up, as directed in this blog post.
I can't see a way around this using the process I've laid out. My solution here is to simply take the expanded MSDeploy.exe command line and use it directly instead of the generated *.deploy.cmd file.
Of course, if anyone comes along with an actual solution to my original problem, I'll happily mark that one as the answer. Until then, this is my solution.
You can put the /M: parameter in quotes like so:
Web.deploy.cmd /Y "/M:https://example.blah:8172/MsDeploy.axd?site=example.blah" /U:user /P:p#44w0rd /A:Basic

Msdeploy not recognizing site name in query string

I am trying to deploy an ASP .NET website using web deploy. I can do it from visual studio and it works. But from the command line it fails, specifically around designating the site name. The output window of visual studio shows me its using:
https://server_name:8172/MsDeploy.axd?site=MyWebSiteDEV
But from the command line if I use this I get an error. Here's my full command:
MyWebSite.Deploy.cmd /T /M:"https://server_name:8172/MsDeploy.axd?site=MyWebSiteDEV" -allowUntrusted /U:DOMAIN\username /P:password /A:Basic
I get the error:
=MyWebSiteDEV"" was unexpected at this time.
I assume there is some kind of escaping problem around the equals sign, but I cant figure out what.
Single quotes around the url solved this problem.
according to this: http://www.jrjlee.com/2011/12/deploying-web-packages-as-non.html
Due to an open bug in the current version of Web Deploy (2.1), you
can’t specify a query string in the endpoint address if you use the
.deploy.cmd file generated by Visual Studio to deploy your web
package. In other words, this won’t work:
DemoProject.deploy.cmd /Y
/M:https://TESTWEB1/MSDeploy.axd?site=DemoSite /U:FABRIKAM\User
/P:Pa$$w0rd A/:Basic -allowUntrusted
I’ve seen some fairly bizarre “workarounds” for this—for example, drop
the query string and use an administrator account—this works, but it
kind of defeats the object when the whole point of the exercise was to
use a non-administrator user to deploy the web package. What you need
to do is to use Web Deploy (MSDeploy.exe) directly rather than running
the .deploy.cmd file.
single quotes doesn't work for me :(

TeamCity - Encrypt Connection Strings?

I've been fighting with TeamCity and cannot get this command to succeed. (It works fine manually.) I've tried many things and surprisingly Google wasn't much help. All I'm trying to do is encrypt the connection strings in my web.config file after a deploy.
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
ASPNET_REGIIS -pef "connectionStrings" "{mypath}"
Error: The configuration for physical path '{mypath}' cannot be opened.
I have it as the 2nd build step after my publish as a Command Line runner type.
I should also mention:
Yes, I'm selecting the folder the web.config is in and not the file itself.
Yes, the path is correct assuming it's supposed to be the one on the server. (C:\inetpub\mysite)
Most Importantly: I'm looking for a solution within TeamCity, not something manual or in my site's code.
Thanks!

Msdeploy replace attribute

I am trying to msdeploy to restore the site on destination computer from the package i created on source IIS 7 site. The destination server IIS is also IIS7.
The destination server however does not have the drive D: as the physical drive. the D: is associated to a CD Row drive.
I use the replace attribute while using msdeploy but the rule does not work.
Below is my command
msdeploy -verb:sync -source:package=d:\site.zip -dest:apphostconfig="Default Web Site" -replace:objectName="metaProperty",scopeAttributeName="name",scopeAttributeValue="Path",targetAttributeName="value",match="d:",replace="c:" -verbose -whatif > msdeploysync.log
However, the -whatif does not show the path changed to C: and also if i run the command, i get message saying "Device not ready" which means that the D: replace is not working.
i am stuck.. any help ?
The provided mechanism for changing the path (in a non-IIS version specific way, mind you) is to set a parameter of kind DestinationVirtualDirectory:
-setParam:kind=DestinationVirtualDirectory,scope="Default Web Site",value="c:\full\path\to\website"
If you would like to strick to simply replacing the drive, try changing your replace directive to this:
-replace:objectName=virtualDirectory,scopeAttributeName=physicalPath,match=^C:,replace=D:
Here's some official docs on the various parameter types: Using declareParam and setParam

(MSDeploy) Deploying Contents of a Folder to a Remote IIS Server

Is it possible to deploy the contents of a folder (plain Html files) to a specific web application on a remote IIS6/7 server?
The following command does not error, but neither does it publish any files to the remote server:
msdeploy.exe -verb:sync -source:dirPath="c:\myHtmlFiles" -dest:auto,ComputerName="http://deploy.mycompany.co.uk/msdeploy?site=TestSite",includeAcls="false",username="administrator",password="myPassword" -enableRule:DoNotDeleteRule -disableLink:AppPoolExtension -disableLink:ContentExtension -allowUntrusted
NOTE:
WebDeploy is correctly installed on the destination server and works happily with packages created from msbuild scripts for .NET projects.
'http://deploy.mycompany.co.uk/msdeploy' is correct for the listening end-point.
The '?site=TestSite' query string was suggested elsewhere, but does not work.
The 'TestSite' web application exists on the target server.
Parameter files and -setParam do not work, and renders errors relating to the source not supporting the parameter 'IIS Web Application Name' if you attempt to set, declare, or provide it.
I just wrote a blog post to answer this at http://sedodream.com/2012/08/20/WebDeployMSDeployHowToSyncAFolder.aspx. From your question it looks like you are pretty familiar with MSDeploy so the answer might be a bit verbose but I wanted people with less knowledge of MSDeploy to be able to understand. I've pasted the answer below.
Web Deploy (aka MSDeploy) uses a provider model and there are a good number of providers available out of the box. To give you an example of some of the providers; when syncing an IIS web application you will use iisApp, for an MSDeploy package you will use package, for a web server webServer, etc. If you want to sync a local folder to a remote IIS path then you can use the contentPath provider. You can also use this provider to sync a folder from one website to another website.
The general idea of what we want to do in this case is to sync a folder from your PC to your IIS website. Calls to msdeploy.exe can be a bit verbose so let’s construct the command one step at at time. We will use the template below.
msdeploy.exe -verb:sync -source:contentPath="" -dest:contentPath=""
We use the sync verb to describe what we are trying to do, and then use the contentPath provider for both the source and the dest. Now let’s fill in what those values should be. For the source value you will need to pass in the full path to the folder that you want to sync. In my case the files are at C:\temp\files-to-pub. For the dest value you will give the path to the folder as an IIS path. In my case the website that I’m syncing to is named sayedupdemo so the IIS path that I want to sync is ‘sayedupdemo/files-to-pub’. Now that give us.
msdeploy.exe –verb:sync -source:contentPath="C:\temp\files-to-pub" -dest:contentPath='sayedupdemo/files-to-pub'
For the dest value we have not given any parameters indicating what server those command are supposed to be sent to. We will need to add those parameters. The parameters which typically need to be passed in are.
ComputerName – this is the URL or computer name which will handle the publish operation
Username – the username
Password – the password
AuthType – the authType to be used. Either NTLM or Basic. For WMSvc this is typically Basic, for Remote Agent Service this is NTLM
In my case I’m publishing to a Windows Azure Web Site. So the values that I will use are:
ComputerName: https://waws-prod-blu-001.publish.azurewebsites.windows.net/msdeploy.axd?site=sayedupdemo
Username: $sayedupdemo
Password: thisIsNotMyRealPassword
AuthType: Basic
All of these values can be found in the .publishSettings file (can be downloaded from Web Site dashboard from WindowsAzure.com). For the ComputerName value you will need to append the name of your site to get the full URL. In the example above I manually added ?site=sayedupdemo, this is the same name as shown in the Azure portal. So now the command which we have is.
msdeploy.exe
–verb:sync
-source:contentPath="C:\temp\files-to-pub"
-dest:contentPath='sayedupdemo/files-to-pub'
,ComputerName="https://waws-prod-blu-001.publish.azurewebsites.windows.net/msdeploy.axd?site=sayedupdemo"
,UserName='$sayedupdemo'
,Password='thisIsNotMyRealPassword'
,AuthType='Basic'
OK we are almost there! In my case I want to make sure that I do not delete any files from the server during this process. So I will also add –enableRule:DoNotDeleteRule. So our command is now.
msdeploy.exe
–verb:sync
-source:contentPath="C:\temp\files-to-pub"
-dest:contentPath='sayedupdemo/files-to-pub'
,ComputerName="https://waws-prod-blu-001.publish.azurewebsites.windows.net/msdeploy.axd?site=sayedupdemo"
,UserName='$sayedupdemo'
,Password='thisIsNotMyRealPassword'
,AuthType='Basic'
-enableRule:DoNotDeleteRule
At this point before I execute this command I’ll first execute it passing –whatif. This will give me a summary of what operations will be without actually causing any changes. When I do this the result is shown in the image below.
After I verified that the changes are all intentional, I removed the –whatif and executed the command. After that the local files were published to the remote server. Now that I have synced the files each publish after this will be result in only changed files being published.
If you want to learn how to snyc an individual file you can see my previous blog post How to take your web app offline during publishing.
dest:auto
In your case I noted that you were using dest:auto, you can use that but you will have to pass in the IIS app name as a parameter and it will replace the path to the folder. Below is the command.
msdeploy.exe
-verb:sync
-source:contentPath="C:\temp\files-to-pub"
-dest:auto
,ComputerName="https://waws-prod-blu-001.publish.azurewebsites.windows.net/msdeploy.axd?site=sayedupdemo"
,UserName='$sayedupdemo'
,Password='thisIsNotMyRealPassword'
,AuthType='Basic'
-enableRule:DoNotDeleteRule
-setParam:value='sayedupdemo',kind=ProviderPath,scope=contentPath,match='^C:\\temp\\files-to-pub$'

Resources