Skip to content

Commit ed163f9

Browse files
committed
Got the App.config file working with correct binding redirects no matter what versions of packages the user installs
Also added some comments to make the install.ps1 file more readable
1 parent 4125742 commit ed163f9

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

AzureWebFarm.OctopusDeploy/AzureWebFarm.OctopusDeploy.nuspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
<files>
4949
<file src="readme.txt" />
5050
<file src="..\ExampleWebFarm\Startup\*.*" target="content\Startup" />
51-
<file src="..\ExampleWebFarm\App.config" target="tools" />
5251
<file src="..\ExampleWebFarm\WebRole.cs" target="content" />
5352
<file src="bin\Release\AzureWebFarm.OctopusDeploy.dll" target="lib\NET45" />
5453
<file src="bin\Release\AzureWebFarm.OctopusDeploy.pdb" target="lib\NET45" />

AzureWebFarm.OctopusDeploy/Tools/install.ps1

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
param($installPath, $toolsPath, $package, $project)
2-
32
$projectPath = Split-Path -Parent $project.FullName
43

4+
# Function to perform xml transform
55
Add-Type -Path ($project.Object.References | Where-Object { $_.Name -eq "Microsoft.Web.XmlTransform" }).Path
66
function 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
2930
if ($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" }
3436
if ($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
}
3739
XmlTransform $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
5651
XmlTransform $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

Comments
 (0)