Skip to content

Commit

Permalink
Fixes #289, bug in MvcSiteMapProvider.Web install.ps1 where missing a…
Browse files Browse the repository at this point in the history
…ppSettings, system.web, system.web.webPages.razor, and system.webServer elements were not being added to the configuration element in the XML. Also fixed logic in install.ps1 and uninstall.ps1 so it will install or uninstall the MVC >= 4 sections without having to update the code for future versions of MVC.
  • Loading branch information
NightOwl888 committed Feb 27, 2014
1 parent 92c20ee commit 9f8d801
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
48 changes: 36 additions & 12 deletions nuget/mvcsitemapprovider.web/tools/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ function Add-Or-Update-AppSettings() {
$web_config_path = Get-Web-Config-Path
$xml.Load($web_config_path)

$conf = $xml.SelectSingleNode("configuration")
if ($conf -eq $null)
{
$conf = $xml.CreateElement("configuration")
$xml.AppendChild($conf)
}

$appSettings = $xml.SelectSingleNode("configuration/appSettings")
if ($appSettings -eq $null) {
$appSettings = $xml.CreateElement("appSettings")
$xml.AppendChild($appSettings)
$conf.AppendChild($appSettings)
}

# add or update MvcSiteMapProvider_UseExternalDIContainer
Expand Down Expand Up @@ -86,10 +93,17 @@ function Add-Pages-Namespaces() {
$web_config_path = Get-Web-Config-Path
$xml.Load($web_config_path)

$conf = $xml.SelectSingleNode("configuration")
if ($conf -eq $null)
{
$conf = $xml.CreateElement("configuration")
$xml.AppendChild($conf)
}

$system_web = $xml.SelectSingleNode("configuration/system.web")
if ($system_web -eq $null) {
$system_web = $xml.CreateElement("system.web")
$xml.AppendChild($system_web)
$conf.AppendChild($system_web)
}

$pages = $xml.SelectSingleNode("configuration/system.web/pages")
Expand Down Expand Up @@ -140,10 +154,17 @@ function Add-Razor-Pages-Namespaces() {
# load Web.config as XML
$xml.Load($web_config_path)

$conf = $xml.SelectSingleNode("configuration")
if ($conf -eq $null)
{
$conf = $xml.CreateElement("configuration")
$xml.AppendChild($conf)
}

$system_web_webpages_razor = $xml.SelectSingleNode("configuration/system.web.webPages.razor")
if ($system_web_webpages_razor -eq $null) {
$system_web_webpages_razor = $xml.CreateElement("system.web.webPages.razor")
$xml.AppendChild($system_web_webpages_razor)
$conf.AppendChild($system_web_webpages_razor)
}

$pages = $xml.SelectSingleNode("configuration/system.web.webPages.razor/pages")
Expand Down Expand Up @@ -216,11 +237,17 @@ function Add-MVC4-Config-Sections() {
$web_config_path = Get-Web-Config-Path
$xml.Load($web_config_path)

# select the node
$conf = $xml.SelectSingleNode("configuration")
if ($conf -eq $null)
{
$conf = $xml.CreateElement("configuration")
$xml.AppendChild($conf)
}

$ws = $xml.SelectSingleNode("configuration/system.webServer")
if ($ws -eq $null) {
$ws = $xml.CreateElement("system.webServer")
$xml.AppendChild($ws)
$conf.AppendChild($ws)
}

$modules = $xml.SelectSingleNode("configuration/system.webServer/modules")
Expand Down Expand Up @@ -302,14 +329,11 @@ if ([string](InferPreferredViewEngine) -eq 'aspx') {
}

# If MVC 4 or higher, install web.config section to fix 404 not found on sitemap.xml (#124)
if ($project.Object.References.Find("System.Web.Mvc").Version -eq "4.0.0.0")
{
Write-Host "Detected MVC 4"
Add-MVC4-Config-Sections
}
if ($project.Object.References.Find("System.Web.Mvc").Version -eq "5.0.0.0")
$mvc_version = $project.Object.References.Find("System.Web.Mvc").Version
Write-Host "MVC Version: $mvc_version"
if ($mvc_version -notmatch '^[123]\.' -or [string]::IsNullOrEmpty($mvc_version))
{
Write-Host "Detected MVC 5"
Write-Host "Installing config sections for MVC >= 4"
Add-MVC4-Config-Sections
}

Expand Down
10 changes: 6 additions & 4 deletions nuget/mvcsitemapprovider.web/tools/uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Remove-AppSettings() {
}

$appSettings = $xml.SelectSingleNode("configuration/appSettings")
if ($appSettings -eq $null) {
if ($appSettings -ne $null) {
if (($appSettings.HasChildNodes -eq $false) -and ($appSettings.Attributes.Count -eq 0)) {
$appSettings.ParentNode.RemoveChild($appSettings)
}
Expand Down Expand Up @@ -198,10 +198,12 @@ function Remove-MVC4-Config-Sections() {
$xml.Save($localPath.Value)
}

# If MVC 4, remove web.config section to fix 404 not found on sitemap.xml (#124)
if ($project.Object.References.Find("System.Web.Mvc").Version -eq "4.0.0.0")
# If MVC 4 or higher, remove web.config section to fix 404 not found on sitemap.xml (#124)
$mvc_version = $project.Object.References.Find("System.Web.Mvc").Version
Write-Host "MVC Version: $mvc_version"
if ($mvc_version -notmatch '^[123]\.' -or [string]::IsNullOrEmpty($mvc_version))
{
Write-Host "Detected MVC 4"
Write-Host "Removing config sections for MVC >= 4"
Remove-MVC4-Config-Sections
}

Expand Down

0 comments on commit 9f8d801

Please sign in to comment.