I am looking for a methodology of how to deploy applications, websites and web services from DEV to ITG and PRO. I am not referring only to files included in the projects, but also settings from IIS, files/folders permissions, etc.
For example, this weekend we had to deploy a new application from ITG to PRO, and PRO AppPool was set to run .NET 2.0 (from previous version). It took us sometime to realize what was going on, leading of course to a longer downtime than expected.
Currently we are using VS 2013, C# 4.x, IIS 8.x and TFS 2013.
The question here is, if there is a way to deploy an application with a "single click". Is MSBuild suitable for this task? (I have no experience on MSBuild, I just found some stuff while Googling, and I am wondering if I need to go deeper). Can TFS read those settings from the source machine and copy them on the target somehow? Is there any other tool than can complete this task? We would like to stay inside Microsoft's circle, however if something else does exactly that, we might consider it.
This can be accomplished via PowerShell. I'm not a PowerShell expert, so my syntax on this is probably not following good practice etc. But I have a script I use to create production and test websites and pre-configure a couple of IIS settings. I then do my deployment from VS, but you could expand the script to perform the build and deployment for you too. It utilizes the WebAdministration module for configuring IIS.
CreateIntranetSite.ps1
param([string]$SiteName, [string]$Hostname)
if($SiteName -eq '') {
Write-Error "You must provide a SiteName parameter."
}
elseif($HostName -eq ''){
Write-Error "You must provide a HostName parameter."
}
else {
Invoke-Command -ComputerName $HostName -credential DOMAIN\mason.sa -ArgumentList $SiteName -ScriptBlock {
param([string]$SiteName)
$IntranetRoot = "E:\Intranet"
$DefaultHtml = "<html><head><title>$SiteName</title></head><body><h1>$SiteName</h1><p>The $SiteName virtual application has been successfully configured.</p></body></html>"
#Import IIS tools
Import-Module "WebAdministration"
#Create Folder
New-Item $IntranetRoot\$SiteName -type Directory
#Create Default Page
Set-Content $IntranetRoot\$SiteName\index.html $DefaultHtml
#Create App Pool
New-WebAppPool $SiteName
#Create Virtual Application
New-WebApplication -Name $SiteName -Site "Intranet" -PhysicalPath $IntranetRoot\$SiteName -ApplicationPool $SiteName
#Configuration Virtual Application
#Disable AnonymousAuthentication
Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/AnonymousAuthentication -name enabled -value false -location Intranet/$SiteName
#Enable Windows Authentication
Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/WindowsAuthentication -name enabled -value true -location Intranet/$SiteName
}
#Launch Browser to verify
$SiteUrl=''
if($HostName -eq 'wr-test01'){
$SiteUrl='https://testnet.termana.net/'+$SiteName
}
elseif($HostName -eq 'wr-web01'){
$SiteUrl='https://intranet.termana.net/'+$SiteName
}
$ie = new-object -com InternetExplorer.Application
$ie.Visible = $true
$ie.Navigate($SiteUrl);
}
Related
I have the following asp.net web application:-
and using this command, i deploy the web application to azure web app:-
az webapp deployment source config-zip --resource-group "PUS" --name "TDMGroupPUSRER" --src "C:\pus\bin.zip"
now when i try to edit the .svc file or delete it i will get "File not found error",as follow:-
So can anyone advice on this?now inside my web application this file contain this code:-
<%# ServiceHost Language="C#" Debug="true" Service="ProjectUpdateSystem.RER" CodeBehind="RER.svc.cs" %>
It's Kudu's problem and there is an open issue for that in in Kudu's github repository.
As an alternative you can use either of the following options for file operations:
Use Azure App Service Editor (Preview)
Use a workaround in PowerShell or command inside Kudu environment
Azure App Service Editor (Preview)
You can find App Service Editor (Preview) under the Development Tools category of your app service blade or you can add /dev at the end of kudu URL. Assuming your application URL is https://myapp.azurewebsites.net/, then it's App Service Editor URL is:
https://myapp.scm.azurewebsites.net/dev/
Then you will be redirected to App Service Editor. Then you can choose the file from the file explorer at left and edit, rename of delete it.
PowerShell
To edit, not a very beautiful workaround, but working:
Kudo → Debug Console → PowerShell
Run the command: Rename-Item sample.svc sample.svc.txt
Edit the file using kudu UI and save changes.
Run the command: Rename-Item sample.svc.txt sample.svc
To delete:
Run the command: Remove-Item sample.svc
To create:
Run the command: New-Item sample.svc
I want to prepare a pre-compiled package of ASP.NET MVC 4 site.
I can precompile it using commandline as follows:
aspnet_compiler -nologo -v / -p "C:\WebSite1" -u "C:\TargetPath"
However it baffles me, why aspnet_compiler requires virtual path. What if I decide later on to deploy this package to an IIS server under different path? Could it cause some run-time problems?
By deployment I mean here simple xcopy deployment.
If you specifiy the physical path of the source with the -p switch, then the virtual path is required. I reluctantly submit this page http://www.asp.net/web-forms/tutorials/deployment/deploying-web-site-projects/precompiling-your-website-cs for some info on how the -v can play in with app relative references ie ~/path/file. What he says needs more qualification and does not appear to apply to apps under the default IIS site.
His explanation is that using -v /MySite will change references from ~/path/file to ~/MySite/path/file. However I have not experienced this behaviour. Atleast as far as compiling apps that are under the default IIS website (regardless of being on the root of the site or nested). If I compile with for instance /v kart, inline references and codebehind references to "~/path/file" arrive in the dll as "~/path/file", not "~/kart/path/file". I have had no runtime problems deploying my WebForm apps elsewhere where the app root is now at a different path.
If you are compiling apps that are under the default IIS website, it is redundant to use -p with the physical path to the source and -v with the virtual path. If you omit the -p switch it will compile the same as only using the -v. Being redundant with the -p and physical source path may be nice when reviewing a batch file to have the source location documented.
The project I have uses msdeploy to publish a package to IIS. It deploys over an existing version of the project. within the web application, I have a virtual directory, but every time I deploy the project, the virtual directory disappears.
I am calling MSDepoly in the following manner:
-source:package='d:\[...]\9.1.0.67\application\AppName.zip' -dest:auto,computerName="hostSite.com",userName="AutoInstall",password="****",authtype="NTLM",includeAcls="False" -verb:sync -enableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"d:\...\9.1.0.67\application\AppName.SetParameters.xml" -skip:objectName=binding -skip:absolutePath="info$" -skip:objectName=dirPath,absolutePath="help$",skipAction=Delete
as you can see at the end, I have the following skip rules:
-skip:objectName=binding -skip:absolutePath="info$" -skip:objectName=dirPath,absolutePath="help$",skipAction=Delete
The binding skip rule is working, but the virtual directory, info, is still getting removed from the web application. the virtual directory is nested within the help directory, so I added the skip action to skip deleting that folder as well.
I based all of this information from the following blog article, but my virtual directory, info, is still getting removed on deployment.
Please help!
I encountered the same issue. In development it appears the following skip rule prevented the Virtual Directory from being removed by MSDeploy.
-skip:ObjectName=virtualDirectory,absolutePath=.*NameOfVirtualDirectory
I gave up on getting msdeploy to play nice. I just wrote a bat script that would be executed after msdeploy completed:
mkdir C:\inetpub\application_wwwroot\VirtualDirectoryPhysicalDir
ECHO adding read permissions to the app pool
cacls C:\inetpub\application_wwwroot\VirtualDirectoryPhysicalDir/t /e /g "IIS APPPOOL\MyAppPool":r
ECHO creating "info" virtual directory
C:\Windows\System32\inetsrv\appcmd add vdir /app.name:"WebApplication/AppVirtualDirectory" / /path:"/help/info" /physicalPath:"C:\inetpub\application_wwwroot\VirtualDirectoryPhysicalDir"
C:\Windows\System32\inetsrv\appcmd set vdir /vdir.name:"Medrio/MedrioWeb/help/info" /physicalPath:"C:\inetpub\application_wwwroot\VirtualDirectoryPhysicalDir"
I would like to deploy a web application on Windows 2008 R2. I know the separate PowerShell commands to do various tasks. But I would like to put this into a nice PowerShell script.
I just need the syntax, can you please help me to do the following actions:
Test if C:\Inetpub\MyWebsite folder exists, if not, create it.
Test in IIS7 if MyWebsite exists, if not create it (I know how to Import-Module WebAdministration and call New-WebSite)
Now the complicated part. I deploy a Web site from a package prepared by Visual Studio 2010. VS supplies a .cmd file where I just need to execute it from a DOS prompt. This means I have to leave the PS Console, open a DOS Console to run that cmd file. Is it possible to run a .cmd file from within a PowerShell console ?
To answer your questions:
Import-Module WebAdministration
# Check for physical path
$sitePath = "c:\inetpub\MyWebsite"
if (-not (Test-Path -path $sitePath))
{
New-Item -Path $sitePath -type directory
}
# Check for site
$siteName = "MyWebSite"
$site = Get-WebSite | where { $_.Name -eq $siteName }
if($site -eq $null)
{
Write-Host "Creating site: $siteName"
# Put your New-WebSite code here
}
# Execute your .cmd here
c:\PathToScript\MakeMySite.cmd
You can run .cmd scripts from within PowerShell just fine.
I have also changed a little bit. Using the same Test syntax to test if a website exists or not:
if (-not (Test-Path -path IIS:\Sites\$SiteName))
{
New-WebSite -Name $SiteName ...etc...
}
Also for executing the *.cmd file, I lift some code from the web and saw that people use & to execute external command. Hope that you are OK:
& c:\PathToScript\MakeMySite.cmd arg1 arg2
Thank you very much for your help.
If you need to run the .cmd file as administrator, you can use the following code:
Start-Process -FilePath C:\PathToScript\MakeMySite.cmd -Verb RunAs -ArgumentList "/y"
I am deploying a website using MSDeploy so using something like the below code.
"%ProgramFiles%\IIS\Microsoft Web Deploy\msdeploy.exe"
-verb:sync
-source:package=WebAppServer.zip
-dest:Auto
-setParamFile="was_params.xml"
-verbose
> webappserversync.log
Is there anyway to set the application pool ? I want to do this from the command line and not set it in a manifest or anything like that.
Shouldn't matter but this is in IIS7.
When you generate your package, you need to have an entry in the parameters.xml file for setting the Application Pool. When deploying, you either include a value for that in your setParameters.xml file, or use -setParam from the command line.
Here is the command I used to grab a site, which generated the proper parameters.xml file ...
msdeploy.exe
-verb:sync -source:appHostConfig="Default Web Site"
-enableLink:AppPoolExtension
-dest:package=site.zip
-declareParam:name="Application Pool",
defaultValue="Default Web Site",
description="Application pool for this site",
kind=DeploymentObjectAttribute,
scope=appHostConfig,
match="application/#applicationPool"
And to install this site from the command line, this ...
msdeploy.exe
-verb:sync
-dest:appHostConfig="MagicSite"
-enableLink:AppPoolExtension
-source:package=site.zip
-setParam:"Application Pool"="MagicPool"
Dig around in the parameters.xml file to see the entry necessary. And if you prefer, that -setParam entry can exist in your params.xml file instead.
Take a look at this answer:
Set application pool with MSDeploy and TFS 2010
Basically, you create a batch file with an adsutil script to set the app pool, and then you call MSDeploy to run that batch file on the target computer.