packages/Microsoft.AspNet.Providers.LocalDB.1.1/tools/Install.ps1
(开头部分) 12KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
param($installPath, $toolsPath, $package, $project)
try {
# Set up variables
$timestamp = (Get-Date).ToString('yyyyMMddHHmmss')
$projectName = [IO.Path]::GetFileName($project.ProjectName.Trim([IO.PATH]::DirectorySeparatorChar, [IO.PATH]::AltDirectorySeparatorChar))
$catalogName = "aspnet-$projectName-$timestamp"
$connectionString ="Data Source=(LocalDb)\v11.0;Initial Catalog=$catalogName;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\$catalogName.mdf"
$connectionStringToken = 'Data Source=(LocalDb)\v11.0;'
$config = $project.ProjectItems | Where-Object { $_.Name -eq "Web.config" }
$fileName = $config.Properties | Where-Object { $_.Name -eq "FullPath" }
#Load the Config File
$xml = New-Object System.Xml.XmlDocument
$xml.Load($fileName.Value)
function CommentNode($node) {
if (!$node) {
return;
}
$commentNode = $xml.CreateComment($node.OuterXml)
$parent = $node.ParentNode
$parent.InsertBefore($commentNode, $node)
$parent.RemoveChild($node)
}
# Comment out older providers
$node = $xml.SelectSingleNode("/configuration/system.web/membership/providers/add[@type='System.Web.Security.SqlMembershipProvider']")
$oldConnectionNode = $xml.SelectSingleNode("/configuration/connectionStrings/add[@name='$($node.connectionStringName)']")
CommentNode $node
CommentNode $oldConnectionNode
$node = $xml.SelectSingleNode("/configuration/system.web/profile/providers/add[@type='System.Web.Profile.SqlProfileProvider']")
$oldConnectionNode = $xml.SelectSingleNode("/configuration/connectionStrings/add[@name='$($node.connectionStringName)']")
CommentNode $node
CommentNode $oldConnectionNode
$node = $xml.SelectSingleNode("/configuration/system.web/roleManager/providers/add[@type='System.Web.Security.SqlRoleProvider']")
$oldConnectionNode = $xml.SelectSingleNode("/configuration/connectionStrings/add[@name='$($node.connectionStringName)']")
$connectionStringsToComment += $node.connectionStringName
CommentNode $node
CommentNode $oldConnectionNode
# Verify that the connectionStrings node exists
$connectionStrings = $xml.SelectSingleNode("/configuration/connectionStrings")
if (!$connectionStrings) {
$connectionStrings = $xml.CreateElement("connectionStrings")
$xml.configuration.AppendChild($connectionStrings)
}
if (!($connectionStrings.SelectNodes("add[@name='DefaultConnection']") | Where { $_.connectionString.StartsWith($connectionStringToken, 'OrdinalIgnoreCase') })) {
# If there aren't any connection strings that look like ours, proceed to add one
$newConnectionNode = $xml.CreateElement("add")
$newConnectionNode.SetAttribute("name", 'DefaultConnection')
$newConnectionNode.SetAttribute("providerName", "System.Data.SqlClient")
$newConnectionNode.SetAttribute("connectionString", $connectionString)
$connectionStrings.AppendChild($newConnectionNode)
}
后面还有 150 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读 AI
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
