Skip to content

Commit

Permalink
Fixes #296, updating MvcSiteMapProvider.Web duplicates MvcSiteMapProv…
Browse files Browse the repository at this point in the history
…ider_IncludeAssembliesForScan setting in web.confg.
  • Loading branch information
NightOwl888 committed Mar 23, 2014
1 parent febc0d8 commit 5ad9833
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
5 changes: 0 additions & 5 deletions nuget/mvcsitemapprovider.web/content/web.config.transform

This file was deleted.

30 changes: 30 additions & 0 deletions nuget/mvcsitemapprovider.web/tools/install.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# install.ps1
param($rootPath, $toolsPath, $package, $project)

Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

function CountSolutionFilesByExtension($extension) {
$path = [System.IO.Path]::GetDirectoryName($project.FullName)
$totalfiles = [System.IO.Directory]::EnumerateFiles("$path", "*." + $extension, [System.IO.SearchOption]::AllDirectories)
Expand Down Expand Up @@ -84,6 +86,23 @@ function Add-Or-Update-AppSettings() {
$appSettings.AppendChild($scan)
}

# add MvcSiteMapProvider_IncludeAssembliesForScan (never update)
$include_scan = $xml.SelectSingleNode("configuration/appSettings/add[@key='MvcSiteMapProvider_IncludeAssembliesForScan']")
if ($include_scan -eq $null) {
$assembly_name = Get-Project-Property-Value "AssemblyName"
$include_scan = $xml.CreateElement("add")

$key = $xml.CreateAttribute("key")
$key.Value = "MvcSiteMapProvider_IncludeAssembliesForScan"
$include_scan.Attributes.Append($key)

$value = $xml.CreateAttribute("value")
$value.Value = "$assembly_name"
$include_scan.Attributes.Append($value)

$appSettings.AppendChild($include_scan)
}

Save-Document-With-Formatting $xml $web_config_path
}

Expand Down Expand Up @@ -321,6 +340,17 @@ function Get-Web-Config-Path() {
return $web_config_path
}

function Get-Project-Property-Value([string] $property_name) {
$ms_build_project = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($Project.FullName) | Select-Object -First 1
foreach ($property in $ms_build_project.Properties) {
if ($property.Name -eq $property_name) {
$value = $property.EvaluatedValue
break
}
}
return $value
}

# Infer which view engine you're using based on the files in your project
if ([string](InferPreferredViewEngine) -eq 'aspx') {
(Get-Project).ProjectItems | ?{ $_.Name -eq "Views" } | %{ $_.ProjectItems | ?{ $_.Name -eq "Shared" } } | %{ $_.ProjectItems | ?{ $_.Name -eq "DisplayTemplates" } } | %{ $_.ProjectItems | ?{ $_.Name -eq "MenuHelperModel.cshtml" -or $_.Name -eq "SiteMapHelperModel.cshtml" -or $_.Name -eq "SiteMapNodeModel.cshtml" -or $_.Name -eq "SiteMapNodeModelList.cshtml" -or $_.Name -eq "SiteMapPathHelperModel.cshtml" -or $_.Name -eq "SiteMapTitleHelperModel.cshtml" -or $_.Name -eq "CanonicalHelperModel.cshtml" -or $_.Name -eq "MetaRobotsHelperModel.cshtml" } } | %{ $_.Delete() }
Expand Down
6 changes: 6 additions & 0 deletions nuget/mvcsitemapprovider.web/tools/uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ function Remove-AppSettings() {
$scan.ParentNode.RemoveChild($scan)
}

# remove MvcSiteMapProvider_IncludeAssembliesForScan
$include_scan = $xml.SelectSingleNode("configuration/appSettings/add[@key='MvcSiteMapProvider_IncludeAssembliesForScan']")
if ($include_scan -ne $null) {
$include_scan.ParentNode.RemoveChild($include_scan)
}

$appSettings = $xml.SelectSingleNode("configuration/appSettings")
if ($appSettings -ne $null) {
if (($appSettings.HasChildNodes -eq $false) -and ($appSettings.Attributes.Count -eq 0)) {
Expand Down

0 comments on commit 5ad9833

Please sign in to comment.