Set application pool with MSDeploy and TFS 2010 - iis

I'm trying to deploy website with MSDeploy and team build using some of this ...
/p:DeployOnBuild
/p:DeployTarget=MsDeployPublish
/p:CreatePackageOnPublish=True
/p:MSDeployPublishMethod=InProc
/p:MSDeployServiceURL=localhost
/p:DeployIISAppPath="Default Web Site"
Is there a way to set this website in custom application pool?

If you're using IIS 7, you can use the appPoolProvider to sync application pools to a remote server. See:
http://technet.microsoft.com/en-us/library/dd569070(WS.10).aspx
and
http://blog.torresdal.net/2010/08/16/NoClickWebDeploymentPart2WebDeployAkaMsdeploy.aspx
However, I wasn't able to really get that to work well, and if you're using IIS 6 this won't work anyway. What you can do though is leverage MSDeploy to run a couple commands on the remote server to set the application pool (and register the .NET version on the website).
First, create a batch file that contains something similar to the following:
cscript //nologo C:\Inetpub\AdminScripts\adsutil.vbs
SET w3svc/<IIS number>/Root/<virtual directory>/AppPoolid "<app pool name>"
So, if the IIS number is 1, your virtual directory is "MyDirectory" and the App Pool is named ".NET4.0", the command would be.
cscript //nologo C:\Inetpub\AdminScripts\adsutil.vbs
SET w3svc/1/Root/MyDirectory/AppPoolid ".NET4.0"
You can then run MSDeploy, passing this batch file in as an argument and running it on the remote machine:
MSDeploy
-verb:sync
-source:runCommand="<path to batch file>",waitinterval=5000
-dest:auto,computername=<computer name>
where <path to batch file> is the full path to the batch file you just created above, and is the computer against which you want to run this. Here is a link describing the runCommand argument: http://technet.microsoft.com/en-us/library/ee619740(WS.10).aspx
I'm sure you can set this up as a build step in TFS. We made a little .NET utility that we call as part of our deployment process that creates these batch files and runs the MSDeploy command.
There are also other things you can do in this same method that might prove useful to you:
Register an IIS version:
%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe
-s w3svc/1/root/MyDirectory
Create an App Pool:
CSCRIPT //nologo %dir%\adsutil.vbs
CREATE w3svc/AppPools/AppPoolName IISApplicationPool
Thanks to http://justsamson.com/2010/06/14/create-virtual-directory-in-iis-6-0-via-command-line/ for the command-line scripts to do the various functionality.

Part of the trick is with /p:IncludeAppPool=true. That changes the deploy script to enable AppPoolExtension. But I haven't figured out how best to actually set the app pool yet. :)

Related

setAclUser issue with msdeploy command line on local machine

I am attempting to deploy a web application on a local IIS machine (IIS 8.0) via msdeploy.exe from a command line.
When I run from the command line:
"%ProgramFiles%\IIS\Microsoft Web Deploy V3\msdeploy.exe"
-verb:sync -source:package=Training.Mvc.Web.zip -dest:auto
-setParam:name="IIS Web Application Name",
value="D:\Release\WebSites\Training" -verbose
I get:
Error: A value for the 'setAclUser' setting must be specified when the 'setAcl'
provider is used with a physical path.
Error count: 1.
I have tried setting the setAclUser after the dest:auto, but that didn't work.
Considering my comment seemed to have done the trick, I thought I'd add it as an answer so the question can be marked as answered.
When you deploy to the file system the aclUser cannot be automatically determined, but if you set your destination to the name of the IIS website (which, tbh, this process was designed for) the application pool identity will be used.

How to setup IIS Express from a script the way Visual Studio does it?

When we configure a web application to run in IIS Express there are certain things VS does, like:
Creating the application host configuration file in the IISExpress subfolder of the user documents folder.
Creating a dedicated site section for each web application in the solution, including ours.
Maybe more things are done, which I am unaware of.
I would like to replicate the same process from a script, so that running the web application from the script would be equivalent to running it from VS. Including for the very first time.
Right now I start IISExpress with the /port and /path flags, because this is how I used to run Cassini. However, Cassini supported an additional flag - /vpath. They removed it from IISExpress, meaning I have to use another set of flags - /config, /site, /siteid. But I suspect it must be done in conjunction with the Appcmd.exe utility.
This second approach is still something I haven't managed to master. So, my question is this - suppose I am given the port, path and vpath of a web application (i.e. no need to read them from the web application's csproj file, like VS does). What command sets up the right application host configuration file and how do I run IISExpress to take advantage of it?

Windows Azure ACS: Unable to find assembly 'Microsoft.IdentityModel"

I have ASP webrole that works great without ACS. When i add ACS to the my application it works fine locally. However when i deploy it to the cloud its doesnt seem to be packaging the Microsoft.IdentityModel.dll.
Now I have done the following:
Ensured under the References that copy local = true for "Microsoft.IdentityModel"
Tired re-adding the STS references.
3.Right click>>Add referance>>Microsoft.IdentityModel.dll
This used to also work fine without having to install WIF on the actual server.
Any ideas?
Please check out these resources, which might help you solving your issue:
Similar SO Question
MSDN Documentation: Unable to Find Assembly 'Microsoft.IdentityModel' When RoleEnvironmentAPIs are Called
ACS Walkthrough from Windows Azure Team (new)
Powershell script on GitHub for Installing WIF via Stratup Task
Hope this helps!
I manage to find what was causing the issue. So I had 1 x WebRole and also 1 X WCF role in the same solution. ACS worked fine up until three steps later in the application once I tried to use the WCF service. At point it stuck me that the Azure creates a VM per role. So this made total since why it authenticated fine up to the point when I tried to use the WCF service. The assembly was not missing from the WebRole but rather from the WCF VM that it created. So I made sure that WIF was also installed on that VM and bang it worked. I still don’t understand 100% why I would have to have to install WIF on the WCF VM but in the end that what was causing my issue.
The only thing that worked for me is described in this post under "using windows update packages section" (but I had to make some minor changes to the startup script)
Basically, I had to create a Startup Task, which executes batch file InstallWif.cmd that I've created under my web project. I also downloaded and included WIF install package (Windows6.0-KB974405-x64.msu) into my web project. I set "Copy to Output Directory" property to "Copy Always" for both of these files.
InstallWif.cmd contained the following script
#echo off
sc config wuauserv start= demand
wusa.exe "%~dp0Windows6.0-KB974405-x64.msu" /quiet /norestart
sc config wuauserv start= disabled
exit /b 0
Note that I had to use Windows6.0-KB974405-x64.msu and not Windows6.1-KB974405-x64.msu. I found out that 6.1 version wouldn't install by logging to Azure VM instance using a remote desktop connection to Azure and trying to manually install this version there.
Startup task is defined inside ServiceDefinition.csdef file like this
<Startup>
<Task commandLine="InstallWif.cmd" executionContext="elevated" taskType="simple" />
</Startup>

MS Deploy - Team Build Drop

Does MS Deploy support the following scenario?
Create a package from a Team Build drop
Install the web application into IIS6/7 including app pools, settings, etc.
It doesn't seem to want to let me configure IIS on the destination server if my package wasn't created from IIS originally.
If you pass the parameter DeployOnBuild set to true, then your build will produce not only your normal web site files under _PublishedWebSites, but also one whose name ends with _Package. That will contain your package, the parameters file and the manifest, plus a .cmd file for deploying the package.
What it will not contain is anything you didn't tell MSBUILD to place into the package. In particular, no, it won't contain IIS settings unless you told MSBUILD to place IIS settings there. It won't get the settings from out of the air - it will only get them from your local IIS, and only if that's where you have your project set up.
The current feature set does not support this scenario - Microsoft

MSDeploy not able to delete files

I've got a TFS build set up to build and deploy a web application. I'm passing in the MSDeploy parameters via the TFS build definition's MSBuild arguments. First time round this is working fine. When someone accesses the web app, one of the controls (Microsoft charting control) generates a couple of files in an empty directory I've added to the solution.
When I go to rebuild (or continuous integration is triggered) the next build will usually fail because it can't delete one of the generated files. When I try and manually delete the file it tells me that IIS worker process is using it and it can't be deleted.
Now to get the build building I'd have to manually restart IIS every time, which is not desirable with CI in mind. I've taken a look through Microsoft.Web.Publishing.Tasks.dll and there's nothing there to restart IIS using MSDeploy.
At the moment I'm thinking that adding stubs of the temporary files in the solution might be a resolution (maybe MSDeploy will be able to close the process if the file is a permanent part of the deployment) or I could do some unpleasantness with Exec in the solution file to get an IIS reset.
It's probably a long shot but has anyone come up against this and found a nice solution?
You could use MSBuild Extension Pack to stop the application pool automatically before deployment. There are several tasks in the MSBuild.ExtensionPack.Web namespace to manage IIS, such as stopping and starting an application pool, deleting an application, etc.

Resources