msdeploy contentPathLib provider replaces wwwroot by approot - msbuild

I am trying to remotely deploy a vNext webapp to iis 7.5 using webdeploy 3.6 and msbuild with the contentPathLib provider as described here.
Here is the msbuild task I use (the source "wwwroot" and "approot" folders are stored in the $(PackageDir), other variables names are selfspeaking)
<Exec Command=""$(MSDeployExe)" -allowUntrusted -verbose -verb:sync -source:contentPathLib="$(PackageDir)wwwroot" -dest:contentPathLib=$(SiteName)/$(ApplicationName),computerName=$(ServerName)/msdeploy.axd?Site=$(SiteName),userName=$(WebDeployUserName),password=$(WebDeployPassword),authtype=basic -enableLink:contentLibExtension" />
The webapp configured in SiteName maps to an empty wwwroot folder.
After msbuild execution, the "wwwroot" folder of the application on the distant server has been renamed to "approot", instead of filling the "wwwroot" and creating a new "approot" folder.
The documentation is still quite poor on the subject (2016-01-14). Has anyone been able to perform a successful webdeploy of a vNext webapp?

I just solved this, I think. The trick seems to be to not define source and dest as contentPathLib, but as iisApp, then enable contentLinkExtension. I'm guessing most of the examples floating around out there involve deploying to IIS on the same server. So your task would be like so:
<Exec Command=""$(MSDeployExe)" -allowUntrusted -verbose -verb:sync -source:iisApp="$(PackageDir)wwwroot" -dest:iisApp=$(SiteName)/$(ApplicationName),computerName=$(ServerName)/msdeploy.axd?Site=$(SiteName),userName=$(WebDeployUserName),password=$(WebDeployPassword),authtype=basic -enableLink:contentLibExtension" />
Full disclosure - I tried this on a Site, not an application within a site.

Related

What decides the output files in MSBuild?

From a CI-CD prospective, i am trying to find what are the folder & files (bin, obj, .dll etc) that are published to an IIS server while using the msbuild.exe with the publish option. I am not a .NET developer. What governs which files/folders to be pushed to the nodes while publishing after the build?
My application is a fairly simple one. The publish (or the deployment) is more or less a bunch of file copies from the CI server to the IIS nodes. The command used for the build and publish is
bat '"C:\\MSBuild\\12.0\\Bin\\MSBuild.exe" /p:Configuration=DEV /t:Rebuild /p:DeployOnBuild=true /p:PublishProfile=DEV /m:4 src/myapp.sln'
I am trying to create & place the required output folder & files to an file repository after the msbuild process (before publishing). Then i will use these files to subsequent environments (with their web config files). Thus avoid the rebuilding for each environments.
In this context MSBuild is actually using WebDeploy under the covers to deploy the application. Basically MSBuild compiles any C# OR VB files in the web application project and creates DLLs in the bin directory, then WebDeploy packages up any web server files (HTML/CSS/JS/etc) and the bin folder to the target.
The following post describes how WebDeploy works.
https://dotnetcatch.com/2016/02/25/the-anatomy-of-a-webdeploy-package/

WebDeploy with MSBuild Not Deploying from TeamCity

I am trying to use MSDeploy to deploy an MVC project to the server using TeamCity. When I do this on my computer in powershell, using the following command:
msbuild.exe .\mvc.csproj /p:PublishProfile=DevServer /p:VisualStudioVersion=11.0
/p:DeployOnBuild=True /p:Password=MyPassword /p:AllowUntrustedCertificate=true
It builds the project and deploys it to the server (info defined in the DevServer publish profile) perfectly. The output shows an MSDeployPublish section at the end, in which I see text like Starting Web deployment task from source... and then with rows telling me what files are updated, etc.
When I run this on TeamCity, using an MSBuild Build step, on the same file, with the same parameters (from the same working directory) it builds the project but does not publish it. Instead it has the regular output from a build process (CoreCompile, _CopyFilesMarkedCopyLocal, GetCopyToOutputDirectoryItems, CopyFilesToOutputDirectory) but then does not actually go and publish anything.
What changes to I need to make to the setup in TeamCity to get it to publish deploy in the same way that it works using MSBuild from my computer?
(TeamCity 7.1, MSBuild 4.0, WebDeploy 3.0, Visual Studio 12, IIS 7. Related to my previous question)
We do our WebDeploys with a TeamCity MSBuild step configured as follows:
Build File Path: Server.csproj
Command Line Parameters:
/p:Configuration=%configuration%
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=https://%web.deploy.server%:8172/MsDeploy.axd
/p:DeployIisAppPath=%web.deploy.site%
/p:AllowUntrustedCertificate=True
/p:Username=
/p:AuthType=NTLM
We use integrated authentication; change as necessary to fit your scheme. The value of this, I think, is that it builds everything from scratch and doesn't rely on a pre-built package. From the gist you posted I noticed that you do some DB publishing, we don't use WebDeploy for that so I can't offer any guidance there. Hope this helps.
I use MSBuild.exe to package to zip, and MSdeploy.exe to deploy in separate steps.
To deploy the package.zip file on the command line:
"C:\Program Files\IIS\Microsoft Web Deploy V2\msdeploy.exe" -verb:sync
-source:package="C:\Build\MyAppName.Debug.zip"
-dest:auto,wmsvc=webservername,username=webdeploy,password=*******
-allowUntrusted=true
This command is also worth explaining in detail:
-verb:sync : makes the web site sync from the source to the destination
-source:package="C:\Build\MyAppName.Debug.zip" : source is an MSBuild zip file package
-dest:auto,wmsvc=webservername : use the settings in the package file to deploy to the server. The user account is an OS-level account with permission. The hostname is specified, but not the IIS web site name (which is previously specified in the MSBuild project file in the project properties).
You can modify parameters based on your configuration. I like it this way because with separate steps, its easier to debug problems.
Use TeamCity build step and the command line runner.
Update:
If you want an example of how to build the ZIP package using MSBuild, try something like this:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
MyWebApp/MyWebApp/MyWebApp.csproj
/T:Package
/P:Configuration=Debug;PackageLocation="C:\Build\MyWebApp.Debug.zip"
This should work the same on your local PC as well as on the CI server.
Here are the config settings that finally worked for me:
/p:Configuration=CONFIG-NAME
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=http://SITE-URL/MsDeployAgentService
/p:username="USERNAME"
/p:password=PASSWORD
/p:AllowUntrustedCertificate=True
/P:CreatePackageOnPublish=True
/p:DeployIisAppPath=SITE-URL
/p:MSDeployPublishMethod=RemoteAgent
/p:IgnoreDeployManagedRuntimeVersion=True
I had exactly the same issue! I've posted the solution I used over at: MsBuild not finding publish profile
Basics were:
Install the Azure SDK 1.8 on the build server
Force the /P:PublishProfileRootFolder value to ensure MSBuild can locate the publish profile
Ensure that you have the Microsoft Web Developer Tools feature installed for Visual Studio. This was missing on my build agent but once I added it the TeamCity build worked just fine.
This can happen when the build target paths are missing from your MSBuild directory. Instead of trying to get those to line up on every developer machine, install the targets from the Nuget. That way it will always be the same for everyone, regardless of how their machine is setup.

MsBuild and MsDeploy problems

When I publish web project by gui(VS2010) (right click in project and choose Publish menu item, publish Method - Web Deploy) - everything works fine.
Problems appear when I am trying to publish via command line: MSBUILD or MsDeploy.
With MSBuild a package is created with no publishing (only creating package):
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe" Project.sln /p:DeployOnBuild=true /p:DeployTraget=MSDeployPublish /p:MSDeployPublishMethod=WMSVC /p:MSDeployServiceUrl=https://[ip]/msdeploy.axd /p:AllowUntrustedCertificate=true /p:DeployIisAppPath=NlbTestSite /p:UserName=M\DeployUser /p:Password=qwerty
With MsDeploy i get an error: ERROR_USER_UNAUTHORIZED
E:\Work\OutDir\MSDeploy\Package.deploy.cmd" /Y /M:"https://[ip]:8172/msdeploy.axd" /U:"M\DeployUser" /P:"qwerty" -allowUntrusted /A:Basic
My goal is to automate the deployment process using one of those methods.
I want to find out how Visual Studio publishes my project (what command with what arguments)?
UPDATE 19.10.2012 14:52
When I add /p:UseMsDeployExe=true, msdeploy.exe is executed, but nothing is copied.
The execution command:
C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe -source:manifest='E:\[Path]\obj\Debug\Package\[Project].SourceManifest.xml' -dest:package='E:\[Path]\[Project]\obj\Debug\Package\[Project].zip',IncludeAcls='False' -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -declareParam:name='IIS Web Application Name',kind='ProviderPath',scope='IisApp',match='^E:\\[Path]\\obj\\Debug\\Package\\PackageTmp$',defaultvalue='[SiteName]',tags='IisApp' -declareParam:name='IIS Web Application Name',kind='ProviderPath',scope='setAcl',match='^E:\\[Path]\\obj\\Debug\\Package\\PackageTmp$' -declareParam:name='Add write permission to App_Data Folder',kind='ProviderPath',scope='setAcl',match='^E:\\[Path]\\obj\\Debug\\Package\\PackageTmp\\App_Data$',description='Add write permission to App_Data folder',defaultvalue='{IIS Web Application Name}/App_Data',tags='Hidden' -declareParam:name='MainModelContainer-Web.config Connection String',kind='XmlFile',scope='E:\\[Path]\\OutDir\\temp\\Web\.config$',match="/configuration/connectionStrings/add[#name='MainModelContainer']/#connectionString",description='MainModelContainer Connection String used in web.config by the application to access the database.',defaultvalue='metadata=[ConnectionString]"',tags='SqlConnectionString' -declareParam:name='SimpleConnection-Web.config Connection String',kind='XmlFile',scope='E:\\[Path]\\OutDir\\temp\\Web\.config$',match="/configuration/connectionStrings/add[#name='SimpleConnection']/#connectionString",description='SimpleConnection Connection String used in web.config by the application to access the database.',defaultvalue='[ConnectionString]',tags='SqlConnectionString' -declareParam:name='ElmahDB-Web.config Connection String',kind='XmlFile',scope='E:\\[Path]\\OutDir\\temp\\Web\.config$',match="/configuration/connectionStrings/add[#name='ElmahDB']/#connectionString",description='ElmahDB Connection String used in web.config by the application to access the database.',defaultvalue='[ConnectionString]',tags='SqlConnectionString' -retryAttempts=2
No parameters, such as ComputerName, User or password are passed.
Any ideas about the cause?
Problem solved.
Got some ideas from http://root-project.org/work/net/automated-web-deployment-with-msbuild-and-msdeploy
I separated msbuild and msdeploy, and executed msdeploy explicitly.
Here is the template:
msdeploy.exe
-source:package=’C:\SomeWebProject\obj\Release\Package\SomeWebProject.zip‘
-dest:auto,ComputerName=’https://TargetServer:8172/MsDeploy.axd?site=TargetWebSite‘,UserName=’Username‘,Password=’Password‘,IncludeAcls=’False’,AuthType=’Basic’
-verb:sync
-disableLink:AppPoolExtension
-disableLink:ContentExtension
-disableLink:CertificateExtension
-allowUntrusted
-retryAttempts=2
-setParam:’IIS Web Application Name’=’TargetWebSite/TargetWebApp‘
But problem with msbuild still remains.
In your pubxml file, declare the following:
<PropertyGroup>
<UseMsDeployExe>true</UseMsDeployExe>
</PropertyGroup>
Now when you deploy, you should see the call to msdeploy.exe in the publih log.
Make note, though, that it will actually be calling msdeploy.exe directly, and not via the generated deploy.cmd file.

How do I use IIS 6 Web Deploy to deploy to a non-default virtual path?

I'm using IIS6, Web Deploy Agent Service, and MSBuild's MSDeploy hooks to deploy. It deploys right now with this set of arguments to MSBuild:
/p:DeployOnBuild=True
/p:DeployTarget=MsDeployPublish
/p:MSDeployServiceURL=example.com
/p:DeployIISAppPath=example.com/DeploySiteName
/p:CreatePackageOnPublish=True
/p:MsDeployPublishMethod=RemoteAgent
/p:AllowUntrustedCertificated=True
/p:UserName=login
/p:Password=pw
With that, it will deploy to C:\Inetpub\wwwroot\wss\VirtualDirectories\example.com80, where the Website files are located.
Unfortunately, I need it to deploy to D:\Webs, mostly for space reasons.
I'm trying to figure out what switch, if any, will allow me to deploy to an alternate physical path and map the virtual directory.
I tried reverse-engineering C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets like another SO post suggested, but I failed... I tried using combinations of these parameters and they had no visible effect:
/p:DeployIisAppPhysicalPath=D:\Webs
/p:RemoteSitePhysicalPath=D:\Webs
Any suggestions?
If you create a virtual folder in IIS6 to point to a different physical location to start with, then pass in the path and parameters like you listed above MSDeploy will write to the correct physical location.

MSBuild 4 and MSDeploy command line

I'm trying to automate deployment of a site. I started with this article
and everything works great from VS 2010. However, I'm having problems with the command line
I use this
c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe "d:\Projects\test.csproj" /T:Package /P:PackageLocation="d:\Package\packageTest.zip"
to create the package
and
d:\Projects\packageTest.deploy.cmd "-setParam:name='IIS Web Application Name',value=MSBuild/Test2" /y
to get to at least deploy correctly.
However, it doesn't take any of the IIS options (the app pool is MSBuild instead of ASP.NET v2.0) and, as I said before, the IIS Web Application Name is wrong.
Shouldn't this information be taken from .csproj file?
All these settings are done for debug configuration and platform any cpu
You typically setup your application on the IIS first, with correct path, application pool and so forth. When setup you can use MSBuild to deploy into that application name like this:
msbuild <your_web_project_name>.csproj /p:Configuration=Release /p:OutputPath=bin /p:DeployOnBuild=True /p:DeployTarget=MSDeployPublish /p:MsDeployServiceUrl=https://<url_to_your_server>:8080/msdeploy.axd /p:username=<username> /p:password=<password> /p:AllowUntrustedCertificate=True /p:DeployIisAppPath=<your_site_name> /p:MSDeployPublishMethod=WMSVC /p:VisualStudioVersion=11.0
If you don't want to setup the site manually, you could run a power shell looking something like this:
Import-Module WebAdministration
New-Item iis:\Sites\<your_site_name> -bindings #{protocol="http";bindingInformation=":80:<your_site_name>} -physicalPath c:\inetpub\wwwroot\<your_site_name>
Set-ItemProperty 'IIS:\Sites\<your_site_name>' ApplicationPool "ASP.NET v4.0"