I am currently trying to get a TFS Build Definition to automatically deploy my web application to the server. The build definition is just a standard manual build definition.
I have create the build definition correctly within the team explorer for my project, and when I queue a build, it completes successfully.
I have set the MSBuild Arguments property in the Build process parameters section to be:
/p:DeployOnBuild=True
/p:Configuration="Release"
/p:DeployTarget=MSDeployPublish
/p:MSDeployPublishMethod=WMSVC
/p:MsDeployServiceUrl=myserver.com
/p:DeployIISAppPath="Default Web Site"
/p:username=username
/p:password=password
/p:AllowUntrustedCertificate=True
/p:SkipExtraFilesOnServer=True
However, when I view my web application in IIS, files that should be there are missing, such as the web.config file.
Right clicking my web application within Visual Studio and publishing via Web Deploy, using the above settings works correctly, and the web.config and other files that were published are shown in the web root.
This is just a development server, so the TFS and IIS are installed on the same machine, and changing the /p:MsDeployServiceUrl to be localhost instead also has no effect.
Is there something I am missing from the Build Definition, or a required parameter to get the TFS build to deploy my web application?
All of the properties you've declared look good, with the exception of the service URL. It needs to point to the full path of the Management Service on your target server.
/p:MsDeployServiceUrl=https://yourserver:8172/msdeploy.axd
The default port for the Management Service is 8172, but if your target has been set up differently, you'll need to adjust.
I'd say get rid of the /p:Configuration="Release" part.
Then go to Process > 1. Required > Items to Build > Configurations to Build and set the configuration there.
Have you try to use a full path for your IIS, for example /p:DeployIISAppPath="Default Web Site/mywebapp
Related
I have a project inside a solution and Visual Studio Team Services is setup to do continuous build.
The test project that includes the Web API project builds fine and even includes the artifacts from the web api project, but when I look at the drop folder from artifacts view it doesn't have a sub folder for the website.
This is done with a new default Visual Studio Build definition with bone stock settings. (no amount of playing around works either)
(I'd put in a screen shot but literally just create a new build definition as choose visual studio and continuous integration and click ok, and that's exactly what this is.)
The log file for the build step doesn't show that it even tries to build the csproj for the web api project and just skips right to the Tests project. (and no errors in the log either)
Going to configuration manager for that configuration (and all configurations) and the project in question is set to build.
It builds properly in that configuration with that project just fine.
It publishes from Visual Studio with that project just fine.
Any ideas why it won't build the project?
According to the information you provided, you are using a default build definition for Visual Studio CI without any other settings. This definition does not generate the web app publish files.
Try adding following MSBuild Arguments in "Visual Studio Build" step and then queue a new build:
/p:DeployOnBuild=true /p:outdir=$(build.artifactstagingdirectory)
Update:
Since you want to deploy the website by Azure Deploy from Release Management, you can just upload the deployment packages to drop. To do this, change the MSBuild Arguments to following:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
And then you can go to Release Managament, in the "Azure Web App Deployment" step, set "Web Deploy Package" to "$(System.DefaultWorkingDirectory)\**\ProjectName.zip".
I am attempting to automate my process for deployments.
Currently, the following steps need run:
Run an external tool in Visual Studio to call Migrator.net (using MSBUILD) to update the database
Right-click the web project and publish locally
Copy the publish folder to all web servers for that specific website
I have now been looking at how to deploy directly from Visual Studio Team Services.
I have created a build definition that will compile my code, and using MSBuild arguments in the "Process" tab of the build definition, will use a publish profile to publish directly to IIS on a target machine. The arguments are something like this:
/p:DeployOnBuild=true;PublishProfile="test_publish.pubxml";UserName=xxx;Password=xxx
This works like a charm for the actual web content, but it does not deal with the database side of things.
The external tool to update the database, as I mentioned, calls MSBUILD with the following:
$(ProjectDir)\Migrations.proj /target:MigrateUAT /p:To=-1 /p:password=xxx
How would I change the build definition to also deal with this MSBuild call? I am at the limit of my MSBuild knowledge.
Thanks in advance.
I have not found out how to do this directly. So I am taking the approach to write a large MSBUILD script that will do everything I want, and only use Team Services to call this script. Rather than use the work flow stuff within the build definition.
I am trying to figure out how to use msdeploy with my MVC site to be able to automate the deployments including setting up IIS on the remote server.
I use the following command to create the package:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe Clients\PokerLeagueWebSite\PokerLeagueWebSite.csproj /T:Package /p:Configuration=Deployment
My setup is as follows:
local dev box using VS2010 + GIT
GITHUB for repo
Teamcity for CI server (different machine to dev box)
remote (same network) UAT server
If I tick the "Include IIS Settings as configured in IIS" and "Include application pool settings used by this web project" and build the package on my dev box then publish from there it works great. Here is the command I use:
C:\myproject\Packages\Deployment\PokerLeagueWebSite>PokerLeagueWebSite.deploy.cmd /Y /M:192.168.10.98:8172 /U:administrator /P:password
This creates the virtual directory within my UAT server and all is well. The problem is when I commit to github and the CI server downloads and builds it. Naturally the virtual directory is not setup on the CI server so the build / package fails.
What I want to do is use the packaging that msdeploy gives and be able to deploy the site and IIS remotely. I guess there are a few options:
1) Alter the MVC project file to hard code iis settings so that when ever / where ever you run the build package it creates the XML files with the correct settings so it can be deployed from any machine. I think this might be able to be done with the package.xml file in the root of the project, but I have no idea how I setup all the app pool and virtual directory settings. Feel like I am half way there but can't get the final push across the line.
2) Use powershell to alter created package XML files so that the extract IIS settings are added.
The first option is preferable as it keeps all the information in one place and you don't need to remember to run an extra script before deployments.
I believe I could figure the second option out by using VS to create the package and get the settings I need then script it, but I don't have a clue and spent a fair while reading about it without any success on how I would do option one.
N.B.
Reading some of the suggested questions before I posted this I can see some sort of possibilities:
MSdeploy deploys an MVC 2 application with wrong virtual directory name
This question talks about passing extra values on the msdeploy command, seems OK but not internal to the build process so to speak. Not sure of all the commands to use but can google that I am sure.
This links seems to continue with the above: http://msdn.microsoft.com/en-us/library/ee814764.aspx
This page takes about the possibilities for option 2. http://learn.iis.net/page.aspx/1082/web-deploy-parameterization/
Think this is the way: using parameters.xml in teh root of the site for project stuff:
http://vishaljoshi.blogspot.com/2010/07/web-deploy-parameterization-in-action.html
EDIT
I have continued reading and testing around this. Using the parameters.xml file in the root of the project I can get the parameters pretty much there I think. My issue seems to be the archive.xml file. This is pretty different and is what is causing the package to not install correctly if I do not have the use IIS settings check box ticked. I have started to read about [project].wpp.targets file that might help but pretty darn lost with that atm.
EDIT 2
So what I think I need to do is get the [project].sourcemanifest.xml file to change a few of its settings. I believe this is what drives the archive.xml which is what is different now. I have the parameters.xml working correctly I think.
When NOT using IIS the sourcemanifest.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<sitemanifest>
<IisApp path="C:\hoh_code\GIT\ai-poker-project\Clients\PokerLeagueWebSite\obj\Deployment\Package\PackageTmp" managedRuntimeVersion="v4.0" />
<setAcl path="C:\hoh_code\GIT\ai-poker-project\Clients\PokerLeagueWebSite\obj\Deployment\Package\PackageTmp" setAclResourceType="Directory" />
<setAcl path="C:\hoh_code\GIT\ai-poker- project\Clients\PokerLeagueWebSite\obj\Deployment\Package\PackageTmp" setAclUser="anonymousAuthenticationUser" setAclResourceType="Directory" />
</sitemanifest>
But when I tick the use IIS settings it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<sitemanifest>
<appHostConfig path="Default Web Site/PokerLeague" />
<contentPath path="C:\hoh_code\GIT\ai-poker-project\Clients\PokerLeagueWebSite\obj\Deployment\Package\PackageTmp" />
<setAcl path="C:\hoh_code\GIT\ai-poker-project\Clients\PokerLeagueWebSite\obj\Deployment\Package\PackageTmp" setAclResourceType="Directory" />
<setAcl path="C:\hoh_code\GIT\ai-poker-project\Clients\PokerLeagueWebSite\obj\Deployment\Package\PackageTmp" setAclUser="anonymousAuthenticationUser" setAclResourceType="Directory" />
</sitemanifest>
Not sure how to change it, working on the [project].wpp.targets file, but fumbling in the dark atm.
EDIT 3
OK so I thought I had it for a minute. in my [project].wpp.targets file I have:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AddContentPathToSourceManifestDependsOn>
SetCustomACLs;
</AddContentPathToSourceManifestDependsOn >
</PropertyGroup>
<Target Name="SetCustomACLs">
<ItemGroup>
<MsDeploySourceManifest Include="appHostConfig">
<Path>Default Web Site/PokerLeague</Path>
</MsDeploySourceManifest>
</ItemGroup>
<ItemGroup>
<MsDeploySourceManifest Include="contentPath">
<Path>$(_MSDeployDirPath_FullPath)</Path>
</MsDeploySourceManifest>
</ItemGroup>
</Target>
</Project>
Which builds, creates a deployment package that I can then deploy from my dev box to the UAT server and it works. But when I run it on my CI server it will not build the deployment package, it drops out at the manifest stage with the error:
One or more entries in the manifest 'sitemanifest' are not valid.
The manifest file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<sitemanifest>
<appHostConfig path="Default Web Site/PokerLeague" />
<contentPath path="C:\TeamCity\buildAgent\work\71e78d4c543e0594\Clients\PokerLeagueWebSite\obj\Deployment\Package\PackageTmp" />
<IisApp path="C:\TeamCity\buildAgent\work\71e78d4c543e0594\Clients\PokerLeagueWebSite\obj\Deployment\Package\PackageTmp" managedRuntimeVersion="v4.0" />
<setAcl path="C:\TeamCity\buildAgent\work\71e78d4c543e0594\Clients\PokerLeagueWebSite\obj\Deployment\Package\PackageTmp" setAclResourceType="Directory" />
<setAcl path="C:\TeamCity\buildAgent\work\71e78d4c543e0594\Clients\PokerLeagueWebSite\obj\Deployment\Package\PackageTmp" setAclUser="anonymousAuthenticationUser" setAclResourceType="Directory" />
</sitemanifest>
I am guessing it is because it still has the IisApp as well as the appHostConfig that I added. I am just guessing about this, and don't know how to remove that yet.
EDIT 4
OK so I found the setting to remove the IISAPP from the manifest and parameters:
<DeployAsIisApp>False</DeployAsIisApp>
This goes into the wpp.targets file.
This has now created a new issue that it will no longer deploy. I believe this is something to do with apphostconfig dealing with sites and iisapp dealing with virtual directories.
EDIT 5
so I have been going through the differences left between ticking with IIS and my custom one.
sourcemanifest.xml files are the same
systeminfo.xml are the same
setparameters.xml:
The IIS web applicaiton name section is different. With IIS version is has the "Default Web Site/pokerleague" value but mine has "C:\websites\pokerleague".
I think this is what is driving the error in the parameters.xml:
the IIS web application has those same values and the tags attribute has physical rather than iisapp.
I have similar tools, and do automated build and deployment:
git repo
vs 2010 , asp.net mvc 3
teamcity 7.1
msbuild
msdeploy
I separate the build, packaging, and deployment steps. I don't use the msdeploy xml files, but do the same thing on the command line.
These are my steps:
Step 1: edit the Visual Studio project properties
right-click "MyAppName" project -> Properties... , tab "Package/Publish Web" ...
Configuration: Active (Debug) - this means the 'Debug' config is active in VS, and you are editing it. The 'Debug' and 'Release' configurations both can be selected and independently edited.
Web Deployment Package Settings - check "Create deployment package as zip file". We want the ZIP file so it can be deployed separately later.
IIS Web Site/application name - This must match the IIS Web site entry on the target server. I use "MyAppName/" with no app name after the path, because i create that in IIS manually. That is how it looks on the web server config.
I create the IIS web site manually the first time (maybe you can automate, i don't). When using MSDeploy, it will push your app to the matching Web Site name - you don't have to hardcode any destination folder paths or anything.
Save it with your project, and make sure your changes are checked into Git (pushed to origin/master). Those settings will be pulled from version control when the CI server runs the build steps.
Step 2: add a Build Step in the TeamCity config
I edit the Build Steps, and add a second build step, to build the MyAppName.sln directly, using msbuild. You can modify as you like, as you probably already do this some way.
Step 3: fix build error by installing Microsoft Visual Studio 2010 Shell (Integrated) Redistributable Package
Basically, either we need to install VS on the build server, manually copy files, or install the Microsoft Visual Studio 2010 Shell (Integrated) Redistributable Package.
Microsoft.WebApplication.targets was not found, on the build server. What's your solution?
This will get it to build. Still no deployment to a server yet.
Step 5: Install the MS Web Deployment tool
I get the Web Deployment Tool here and install. After reboot, the TeamCity login has a 404 error. Turns out Web Deploy has a service which listens on port 80, but so does TeamCity Tomcat server. For short term, i stop the Web Deploy web service in control panel, and start the TeamCity web service. The purpose of the Web Deployment Agent Service is to accept requests to that server from other servers. We don't need that, because the TeamCity server will act as a client, and deploy out to other web servers.
The Web Deployment Tool also has to be installed on the target web server. I'm not going to go too far into detail here, but you have to configure the service to listen as well, so when you run the deployment command, it accepts it and installs on the server. For the server, i set up a new account named 'webdeploy' with permission to install.
Step 6: Create a MSBuild command to package the Web project
I do separate steps for packaging and deployment. This will allow cases for building a Release package but manually deploying it, if you want.
This is the msbuild package command:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
MyAppName/MyAppName/MyAppName.csproj
/T:Package
/P:Configuration=Debug;PackageLocation="C:\Build\MyAppName.Debug.zip"
Let me explain the command parts:
MyAppName.csproj : path to VS project file to build. There are important options in there which get set from the project Properties tabs.
/T:Package : create a ZIP package
/P:Configuration=Debug;PackageLocation=*** : run the Debug configuration. This is the same as Build in Visual Studio with the 'Debug' setting selected. The 'Package Location' is what it created. We will reference the package file later in the deployment command.
Step 7: Create a Web Deploy command to deploy the project ##
"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).
After deployment, i checked the IIS web server files, to make sure they had the latest DLLs and web.config file.
Step 8: Call the MSDEPLOY from the TeamCity build steps
Since there are now have 2 good commands (MSBUILD.exe to package, MSDEPLOY.exe to deploy), add them to the build steps. I use the command line runner, and just put in the same command as the prior 2 steps.
run it all
When you run the build with these steps, if they succeed, you have automatic deployment directly from git.
Now every time new code gets merged and pushed to git origin/master branch, it will automatically build and deploy the the development server.
As you can see, this avoids your original problem:
The problem is when I commit to github and the CI server downloads and
builds it. Naturally the virtual directory is not setup on the CI
server so the build / package fails.
The CI server only builds and packages. Then it deploys to the target web server.
Take a look at Appveyor. We've just released v2.0 and IMHO it is a really strong alternative to WebDeploy. The entire deployment process could be scripted through PowerShell on CI server and there are PS hooks to customize the process.
Disclaimer: I'm Appveyor developer. I'm not trying to advertise here, but it would be great to see if that works for you.
So, here is the deal. In web app project settings I configured a deployment package which includes all content files along with IIS settings for the site & app pool. Now, when i go to Team Build build config, I use the following arguments to deploy the site.
/p:UseWPP_CopyWebApplication=True
/p:PipelineDependsOnBuild=False
/p:DeployOnBuild=True
/p:DeployTarget=MsDeployPublish
/p:CreatePackageOnPublish=True
/p:MSDeployPublishMethod=WMSVC
/p:MSDeployServiceUrl=https://<servername>:8172/MsDeploy.axd
/p:AllowUntrustedCertificate=True
/p:DeployIisAppPath="mysite.com"
/p:UserName=<domain>\<user>
/p:Password=<password>
While this actually works, the deployment will fail if "mysite.com" site doesn't exist on the destination server or if the app pool isn't set up correctly (i.e. ASP.NET version mismatch). So i find myself creating this stuff manually before i can deploy anything from Team Build. Is there a way to automate this? Am i missing some kind of argument switch? I guess another way to phrase this question, is why do i have to set all this up when the package includes all of IIS settings and should just deploy.
Thanks for any help/explanation.
EDIT:
I'm not entirely sure if this is true, but i believe i will not be able to do create site/app pool. From my understanding of things, Team Build uses msbuild to talk to msdeploy and that link is very limited in what it can do. So, I may be looking at changing the build workflow template to execute the command line to deploy the package (?).
Check out the TechNet documentation on the iisApp provider at
http://technet.microsoft.com/en-us/library/dd569054(WS.10).aspx. Of the four parameters, these are the ones you'd probably be interested in:
managedRuntimeVersion
skipAppCreation
I've been reading and experimenting for days. I bought the latest "Inside the Microsoft Build Engine - Using MSBUild and Team Foundation Build". I've been trying to figure things out by looking at the build targets.
I was quickly able to get a package to be built on the build server, but I want to be able to specify the installation folder, so it doesn't go into wwwroot. I read that I would have to switch the project over from using cassini to the local IIS server. Went through all of that.
The args I'm passing to msbuild through the definition:
/p:DeployOnBuild=true /p:DeployTarget=Package /p:MSDeployPublishMethod=InProc /p:CreatePackageOnPublish=True /p:MsDeployServiceUrl=localhost
I've got SO MANY questions, but I'll start simply. If anyone can provide guidance I'd be super thankful.
If the named application doesn't exist on the build server (which it shouldn't!) the package creation fails. If I add a shell app named accordingly the package is built.
Even if I hack my way past #1 when I try to deploy using Web.deploy.cmd, it fails:
Error: Using a 64-bit source and a 32-bit destination with provider appHostConfig is not supported.
Note that the build server is 64-bit and THIS target server (development) is 32-bit. I have the build configuration building against "any cpu". Oh, and I'm invoking the deployment FROM the 32-bit machine, so there's only the 32-bit msdeploy.exe available.
In the appropriate BuildDefinition under "Process", expand the "Advanced" section and set the value of "MSBuild Arguments" to "/p:DeployOnBuild=True".
That will make your WebDeploy Package built according to your settings in the project properties.
I write 2 articles about how to create Web Package and auto deploy it to a Web Server, I think it maybe useful for you.
Auto Deploy your Website for QA with Team Build click here
How to run remote deploy with MS Deploy? click here