問題現象 html
Visual Studio在開發SharePoint的時候,發佈部署包後,首次打開及調試站點頁面的時候會很是的慢web
解決方案 shell
使用PowerShell腳本,加載SharePoint插件後遍歷全部的網站集,用以模擬用戶自動點擊頁面api
具體步驟 網站
因爲SharePoint運行的是64位的PowerShell,而Visual Studio的Post-build event中默認運行的32位的PowerShell,須要找到一個變通的方式ui
新建一個Console程序,其中代碼以下url
using System; spa using System.Diagnostics; 插件
namespace ConsoleApplicationExample 調試 { class Program { static int Main(string[] args) { Process process = Process.Start("PowerShell.exe", String.Join(" ", args)); process.WaitForExit(); return process.ExitCode; } } } |
同時找到VS目錄下64位的CMD,運行以下命令生成PowerShell的64位版本
csc Path to cs file\Program.cs /platform:x64 |
到目錄c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC中找到Program.exe,並重命名爲PowerShell64.exe
機器上運行PowerShell須要開啓權限,運行如下腳本(注意:須要開啓64位的權限)
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe %SystemRoot%\sysWOW64\WindowsPowerShell\v1.0\powershell.exe |
Set-ExecutionPolicy Unrestricted |
在PowerShell中操做SharePoint對象(遍歷網站)
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin Microsoft.SharePoint.PowerShell }
function Get-WebPage([string]$url) { $wc = new-object net.webclient; $wc.credentials = [System.Net.CredentialCache]::DefaultCredentials; $pageContents = $wc.DownloadString($url); $wc.Dispose(); return $pageContents; }
Get-SPAlternateUrl -Zone Default | foreach-object { write-host $_.IncomingUrl; $html = Get-WebPage -url $_.IncomingUrl; } |
$(ProjectDir)\PowerShell\PowerShell64.exe -File $(ProjectDir)\PowerShell\warmupAllSharePointSites.ps1 |