Continuous Testing of PowerShell Scripts with Visual Studio
Alex RandallSenior Consultant
http://blogs.msdn.com/b/alex_randall
Continuous Testing of PowerShell Scripts with Visual StudioAgendaSharePoint 2013 PreviewVisual Studio 2012Deploying SharePoint solutions to production farmsAnatomy of a sample SharePoint PowerShell deploy scriptIntegrating a SharePoint PowerShell deploy script into Visual StudioHow to create your own SharePoint PowerShell deploy scripts
SharePoint 2013 PreviewWill this Visual Studio/PowerShell technique apply to SharePoint Preview?Yes!
(However, for this session, I will focus on SharePoint 2010 for demos)
SharePoint Foundation
2013 Preview
SharePoint Server 2013
Preview
Office 365 SharePoint
Server 2013 Preview
http://dev.office.com
http://technet.microsoft.com/en-us/sharepoint/fp142366
Let’s just jump right in to Visual Studio 2012! (DEMO!)
Visual Studio 2012
What we just saw…
Lots going on behind the scenes during deployDeactivating featuresUninstalling featuresRetracting the solutionUninstalling the solutionInstalling the solutionDeploying the solutionInstalling featuresActivating features
Integrated automatic F5 deploy functionality
Deploying to farms – who?
Visual StudioSharePoint
FarmI’m done! I’m ready to have this installed on the _________ farm
Developer does deployPotential to “take down the farm” for several seconds if farm based solutionPotential to cause conflicts with other deploying, testing, or demos going on, etc.SharePoint Administrator does deployMore control, however, deploying custom solutions to farms is just 1% of their jobTakes time for them to do itDeveloper has to document the deploy process for them
Deploying to farms – How?
Visual Studio
SharePoint Development
Farm
SharePoint Testing Farm
SharePoint Production
Farm
I’m done! I’m ready to have this installed on the _________ farm
For one farmInstall options:
1) manually through the UI(very time consuming!)(room for human error)
2) PowerShell(one click!)
3) other ways…
For multiple farmsRepeat steps above*Production farms need special care
PowerShell Deploy AdvantagesFrees SharePoint Administrators upTo focus on real issues such as helpdesk issues, farm stability, reliability, performance, maintenance, as well as planning for future service offerings.
Consistent Deploy ExperienceLessens possibility of human error across farms
Full control of what gets deployed and whereImagine a complex deployment across 45 site collections and 200 subsites each…
If developer writes scripts, they have intimate knowledge of their own solution
Anatomy of a deploy scriptDeactivate featuresUninstall featuresRetract the solutionUninstall the solutionInstall the solutionDeploy the solutionInstall featuresActivate features
Let’s see it in action!
DEMO: Sample SharePoint PowerShell Deploy script for a custom SharePoint solution
PowerShell recommended practicesPut LOTS of comments in the scriptPut all variables at the topEnsure script stops immediately if error occursEnsure proper disposal of all SharePoint disposable objectsEnsure you are calling the correct parameters on each SharePoint Cmdlet for your exact scenarioAutomatically load the SharePoint Cmdlets if they are not present
Integrating into Visual Studio!
DEMO: How to do the real magic! Continuous testing of PowerShell Scripts with Visual Studio!
What we just saw…1) Visual Studio must be run in Administrator Mode2) In the SharePoint Post Deployment Command:Copy the msbuild file to the bin directoryCopy the PowerShell scripts to the bin directoryExecute msbuild in 64 bit mode to run PowerShell in 64 bit mode and load the script
3) Create a SharePoint deployment option to only run the Post Deployment command
Not clear on these steps? No problem! I’ve documented them here with screenshots: http://blogs.msdn.com/b/alex_randall
Benefits of Continuous Testing of PowerShell Scripts with Visual Studio
RepeatabilityMaintainabilityConsistency Robustness
How to create your own scripts1) Start from a good example2) Think about your exact deploy scenario3) Build your script “line by line” in
interactive PowerShell3) Read the documentation for each
SharePoint PowerShell Cmdlet to ensure you are using the proper parameters for your deploy scenario
4) Ensure you are following recommend practices
Creating your PowerShell Script
DEMO: How to create a SharePoint PowerShell Deploy script
Summary: Continuous Testing of PowerShell Scripts in Visual Studio
Why Recommended PracticesHow
Everything I showed you is located at: http://blogs.msdn.com/b/alex_randall
Thanks to our sponsors!
Continuous Testing of PowerShell Scripts with Visual Studio
Alex RandallSenior Consultant
http://blogs.msdn.com/b/alex_randall
Top Related