如何通过PowerShell在Visual Studio的Post-build中预热SharePoint站点
问题现象
Visual Studio在开发SharePoint的时候,发布部署包后,首次打开及调试站点页面的时候会非常的慢
解决方案
使用PowerShell脚本,加载SharePoint插件后遍历所有的网站集,用以模拟用户自动点击页面
具体步骤
- 制作"64位版本"的PowerShell
由于SharePoint运行的是64位的PowerShell,而Visual Studio的Post-build event中默认运行的32位的PowerShell,需要找到一个变通的方式
新建一个Console程序,其中代码如下
|
using System; 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; } |
- 配置Visual Studio

|
$(ProjectDir)\PowerShell\PowerShell64.exe -File $(ProjectDir)\PowerShell\warmupAllSharePointSites.ps1 |
如何通过PowerShell在Visual Studio的Post-build中预热SharePoint站点的更多相关文章
- 在 Visual Studio 等编辑器/IDE中自动切换输入法,不需要手动的有没有?
使用Visual Studio写代码,经常遇到的一个问题就是切换中文输入法麻烦,输入完注释//,要切换到中文,输入完引号,要输入中文,然后还需要切换回来,有没有? 有时候中文输入法忽然失效有没有?明明 ...
- 【转】【UML】使用Visual Studio 2010 Team System中的架构师工具(设计与建模)
Lab 1: 应用程序建模 实验目标 这个实验的目的是展示如何在Visual Studio 2010旗舰版中进行应用程序建模.团队中的架构师会通过建模确定应用程序是否满足客户的需求. 你可以创建不同级 ...
- Visual Studio下Qt编程中对中文的处理
Visual Studio下Qt编程中对中文的处理 本文为原创文章,原文地址http://www.cnblogs.com/c4isr/p/qt_develop_in_vs.html Visual St ...
- 在visual studio的工程项目应用中打开console控制窗口
在visual studio的工程项目应用中打开console控制窗口,这个可以方便我们在console中输出参数的值检查错误. 只需要在需要打开console的地方加入下面的代码即可. AllocC ...
- 用DebuggerDisplay在Visual Studio的调试器中定制类的显示方式
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:用DebuggerDisplay在Visual Studio的调试器中定制类的显示方式.
- Visual Studio - File Properties (Build Action, Copy to Output Directory)
Ref: MSDN (https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/0c6xyb ...
- Visual Studio扩展与更新中插件被禁用,安装后无法使用
在Visual Studio中的扩展与更新中安装插件后,显示[禁用],重新安装后仍然不能使用,但是VS默认安装的扩展却可以正常使用. 这里需要注意下方显示“当前不允许加载每用户扩展”,点击“启用每用户 ...
- 如何使用Visual Studio 2010在数据库中生成随机测试数据
测试在项目中是很重要的一个环节,在Visual Studio 2010中,在测试方面已经有很好的支持了,比如有单元测试,负载测试等等.在数据测试的方面,Visual Studio 2010,还支持对数 ...
- 在Visual Studio开发的项目中引用GAC中的dll
Open the windows Run dialog (Windows Key + r) Type C:\Windows\assembly\gac_msil. This is some sort o ...
随机推荐
- android手势创建及识别
使用一些浏览器或者输入法应用时会有一些手势操作,还可以自定义手势.这些神奇的操作是怎么做的呢?这一篇重点记录手势的识别和创建.这篇的内容使用到的是android.gesture包,具体的例子参考的是S ...
- Surface Shader
Surface Shader: (1)必须放在SubShdader块,不能放在Pass内部: (2)#pragma sufrace surfaceFunction lightModel [option ...
- 2014 网选 5011 Game(Nim游戏,数学题)
/* 题意:Nim游戏! 思路:通过异或,判断将n个数表示成二进制的形式之后,是否对应位的数字1 的个数是偶数! */ #include<iostream> using namespace ...
- iOS-分段控制器-基本概念
可以直接复制使用 #import "FirstViewController.h" #import "Masonry.h" @interface FirstVie ...
- LeetCode——Find the Duplicate Number
Description: Given an array nums containing n + 1 integers where each integer is between 1 and n (in ...
- Direct3D11学习:(五)演示程序框架
转载请注明出处:http://www.cnblogs.com/Ray1024 一.概述 在此系列最开始的文章Direct3D11学习:(一)开发环境配置中,我们运行了一个例子BoxDemo,看过这个例 ...
- Team Foundation Server简介
对于任何一个软件开发团队而言,成功的一个重要因素在于成员之间.成员与首先使用软件的用户之间有很好的沟通. Team Foundation Server是一个独立的服务器产品,逻辑上,由下列两层组成,这 ...
- [JS] jQuery选择器
jQuery 选择器 选择器 实例 选取 * $("*") 所有元素 #id $("#lastname") id=lastname 的元素 .class $(& ...
- 2016校招内推 -- 腾讯SNG前端 -- 面试经历
也是让某湿兄帮忙内推,然后过了四五天,电话打来了 一面: 1.首先是简单的自我介绍 2.你觉得一个前端工程师应该具备什么技能 比如用户体验这个方面他就贵问你具体的例子 3.让你设计一个web站点,假如 ...
- 2015年百度之星初赛(1) --- C 序列变换
序列变换 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...