11param ($installPath , $toolsPath , $package , $project )
2-
32$projectPath = Split-Path - Parent $project.FullName
43
4+ # Function to perform xml transform
55Add-Type - Path ($project.Object.References | Where-Object { $_.Name -eq " Microsoft.Web.XmlTransform" }).Path
66function XmlTransform ([string ] $file , [string ] $transformFile ) {
77
@@ -25,36 +25,32 @@ function XmlTransform([string] $file, [string] $transformFile) {
2525 }
2626}
2727
28+ # Find Cloud project
2829$ccProj = $project.Object.DTE.Solution.Projects | Where-Object { $_.Kind -eq " {cc5fd16d-436d-48ad-a40c-5a424c6e3e79}" } | Select-Object - First 1
2930if ($ccProj -eq $null ) {
3031 throw " Couldn't find an Azure Cloud Project in your solution; please follow the instructions at https://github.com/AzureWebFarm.OctopusDeploy"
3132}
3233
34+ # XDT Transform CSDef file
3335$csdef = $ccProj.ProjectItems | Where-Object { $_.Name -eq " ServiceDefinition.csdef" }
3436if ($csdef -eq $null ) {
3537 throw " Couldn't find a ServiceDefinition.csdef file in Azure Cloud Project $ ( $ccProj.Name ) ; please follow the instructions at https://github.com/AzureWebFarm.OctopusDeploy"
3638}
3739XmlTransform $csdef.Object.Url (Join-Path $toolsPath " ServiceDefinition.csdef.xdt.xml" )
3840
39- $csdef = $ccProj.ProjectItems |
41+ # XDT Transform CSCfg files
42+ $ccProj.ProjectItems |
4043 Where-Object { $_.Name.EndsWith (" .cscfg" ) } |
4144 ForEach-Object { XmlTransform $_.Object.Url (Join-Path $toolsPath " ServiceConfiguration.cscfg.xdt.xml" ) }
4245
43- $toolAppConfig = Join-Path $toolsPath " App.config"
44- Write-Host " Adding $toolAppConfig to $ ( $project.Name ) project"
45- $projAppConfig = Join-Path $projectPath " App.config"
46- if (-not (Test-Path $projAppConfig )) {
47- Copy-Item $toolAppConfig $projAppConfig
48- $project.ProjectItems.AddFromFile ($projAppConfig )
49- }
50-
51- Write-Host $toolsPath
46+ # XDT Transform CCProj file
5247$tempFile = [IO.Path ]::GetTempFileName()
5348$xdt = Get-Content (Join-Path $toolsPath " CloudProject.ccproj.xdt.xml" )
5449$assemblyName = ($project.Properties | Where-Object { $_.Name -eq " AssemblyName" } | Select-Object - First 1 ).Value
5550$xdt.Replace (" %WebProjectName%" , $project.Name ).Replace(" %WebProjectDir%" , $projectPath ).Replace(" %WebAssemblyName%" , $assemblyName ) | Set-Content $tempFile
5651XmlTransform $ccProj.FullName $tempFile
5752
53+ # Set Startup items as copy always
5854$startupFolder = $project.ProjectItems |
5955 Where-Object { $_.Name -eq " Startup" } |
6056 Select-Object - First 1
@@ -63,3 +59,20 @@ $startupFolder.ProjectItems |
6359 Write-Host " Setting Startup\$ ( $_.Name ) as Copy always"
6460 $_.Properties.Item (" CopyToOutputDirectory" ).Value = [int ]1
6561 }
62+
63+ # Add binding redirects for web.config
64+ Write-Host " Adding binding redirects to update Web.config"
65+ Add-BindingRedirect
66+
67+ # Add App.config file with binding redirects
68+ Write-Host " Creating an App.config file for use by the RoleEntryPoint with the binding redirects in Web.config"
69+ $webConfigProjectItem = $project.ProjectItems | Where-Object { $_.Name -eq " Web.config" } | Select-Object - First 1
70+ $webConfigPath = ($webConfigProjectItem.Properties | Where-Object { $_.Name -eq " LocalPath" } | Select-Object - First 1 ).Value
71+ $webConfig = [xml ] (Get-Content $webConfigPath )
72+ $runtimeNode = $webConfig.configuration.runtime
73+ $appConfig = [xml ]" <?xml version=`" 1.0`" ?><configuration />"
74+ $newRuntimeNode = $appConfig.ImportNode ($runtimeNode , $true )
75+ $appConfig.DocumentElement.AppendChild ($newRuntimeNode )
76+ $appConfigPath = Join-Path $projectPath " App.config"
77+ $appConfig.Save ($appConfigPath )
78+ $project.ProjectItems.AddFromFile ($appConfigPath )
0 commit comments