ASP.NET Classic Example
This blog is part of the series of Continuous Delivery Automation Framework use cases.
Tokenisation of Web Deploy settings file
This content has been moved from the generic CDAF Docs material as it distracted from the common concepts.
In this example, a ASP.NET solution is build is being performed to create a Web Deploy package. Generic properties can be tokenised in the Web.Release.config
.
<connectionStrings>
<add name="entities"
connectionString="metadata=res://*/Models.mydb.csdl|res://*/Models.mydb.ssdl|res://*/Models.mydb.msl;provider=System.Data.SqlClient;provider connection string="data source=%spnDBHost%;initial catalog=%spnDBName%;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
The construction of web deploy settings for the deploy path is not intuitive and is no longer (after 2010) accessible via the Visual Studio user interface. Edit the .csproj
file directly for the Release
property group.
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DeployIisAppPath>%25webAppSite%25/%25webAppName%25</DeployIisAppPath>
</PropertyGroup>
In the CDAF.solution:
productVersion=2.3
The EXITIF
operation allows the skipping of the build prcess if the built-in variable $ACTION
has been set to clean
. The MSTOOL
operation loads the path to MSBuild.exe into environment variable $env:MS_BUILD
. The REPLAC
operation detokenises static content file to inject the product version, which includes the built in $BUILDNUMBER
. Then the compile of the code and generation of Web Deploy (/T:Package
) artefacts is performed:
REMOVE bin
REMOVE obj
Write-Host "If Action is clean only, then exit`n"
EXITIF $ACTION -eq "clean"
Write-Host "Combine to create symantic (http://semver.org/) version`n"
ASSIGN $productVersion+='.'
ASSIGN $productVersion+=$BUILDNUMBER
MSTOOL
Write-Host "PROJECT : $($PROJECT)"
Write-Host "`$productVersion : $productVersion`n"
Write-Host "[$PROJECT] Apply product version as static content`n"
REPLAC Views\Shared\_Layout.cshtml %productVersion% $productVersion
Write-Host "[$PROJECT] Build Project ($PROJECT) with specific parameters for web deploy.`n"
& "$env:MS_BUILD" $PROJECT.csproj /T:Package /P:Configuration=Release /p:buildNumber=$productVersion
The resulting build is a directory files, which need to be included in your storeFor
definition for packaging
<projectname>\obj\Release\Package\<projectname>.deploy.cmd -Flat
<projectname>\obj\Release\Package\<projectname>.SetParameters.xml -Flat
<projectname>\obj\Release\Package\<projectname>.zip -Flat
The SetParameters.xml will contain the DeployIisAppPath
from the .csproj
file edited above. So now configuration management can be applied at deploy time.
context target webAppSite webAppName spnDBHost spnDBName
local TEST "Default Web Site" test nonprod test
local TEST "Default Web Site" uat nonprod uat
local PROD "Default Web Site" prod prodsql prod
During (Local)[https://docs.cdaf.io/mydoc_basics_local_tasks.html] or (Remote)[https://docs.cdaf.io/mydoc_basics_remote_tasks.html] deployment. The deployment task can now detokenise all properties for the application deployment.
Write-Host "Detokenise the settings for this environment`n"
DETOKN aspdotnet.SetParameters.xml
Write-Host "Use Web Deploy to deploy the Aware application`n"
.\<projectname>.deploy.cmd /Y /M:localhost