2
下面的代碼工作時,當我不使用.NET 4.0 Framwork問題與朝鮮勞動黨使用PowerShell工具.NET4
ipmo WPK
$ConnectionString = $ConnectionString = "Server=localhost;Integrated Security=True"
$conn = new-object System.Data.SQLClient.SQLConnection
$conn.ConnectionString = $ConnectionString
$conn.Open()
function Invoke-sql1
{
param([string]$sql,
[System.Data.SQLClient.SQLConnection]$connection
)
$cmd = new-object System.Data.SQLClient.SQLCommand($sql,$connection)
$ds = New-Object system.Data.DataSet
$da = New-Object System.Data.SQLClient.SQLDataAdapter($cmd)
$da.fill($ds) | Out-Null
return $ds.tables[0]
}
function Show-Bockmarks ($resource) {
New-Window {
New-Grid -ColumnDefinitions @(
New-ColumnDefinition -Width 900*
) -RowDefinitions @(
New-RowDefinition -Height 30
New-RowDefinition -Height 600*
) {
New-StackPanel -Orientation horizontal -column 0 -row 0 -Children {
New-Button -Name Search "Press me" -On_Click {
$ff_sql = @"
SELECT 'abc' title, getdate() dateAdded , 'xyz' url
UNION
SELECT 'efg' title, getdate() dateAdded , 'xyz' url
"@
$conn = $resource.conn
$window.Title = "$($conn.database) Database Browser"
$TableView = $window | Get-ChildControl TableView
$TableView.ItemsSource = Invoke-sql1 -sql $ff_sql -connection $conn
}
New-Button -Name Cancel "Close" -On_Click {$window.Close()}
}
New-ListView -Column 0 -Row 1 -Name TableView -View {
New-GridView -AllowsColumnReorder -Columns {
New-GridViewColumn "title"
New-GridViewColumn "dateAdded"
New-GridViewColumn "url"
}
}
}
} -asjob -Resource $resource
}
Show-Bockmarks -resource @{conn = $conn}
按顯示我按鈕和電網3行罷了。
但是,當我加入powershell_ise.exe.Config這樣
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319" />
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>
我收到以下錯誤使用.NET 4.0框架:
Add-Type : c:\Users\berndk.MMEDVNT\AppData\Local\Temp\eps22jnq.0.cs(24) : The type 'System.Windows.Markup.IQueryAmbient' is defined in an assembly that is not referenced. You must add a
reference to assembly 'System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
我想,在某些情況下使用帶-asJob的WPK導致了這個問題,但我不確定。
好的,更新。我看起來更接近:) – x0n 2011-05-01 15:39:26
固定。 OP可以做出這些微小的改變。 – x0n 2011-05-01 19:31:06