Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Building SharePoint 2010 Customisations with Visual Studio 2010: Overview and Tips

3,445 views

Published on

This presentation is from the Christchurch SharePoint User Group and presents 3 tips/tricks/issues when building customisations for SharePoint 2010 using Visual Studio 2010.

Published in: Education, Technology
  • Be the first to comment

Building SharePoint 2010 Customisations with Visual Studio 2010: Overview and Tips

  1. 1. Nick Hadlee @nickhadlee http://hadlee.net.nz SharePoint Development: Visual Studio 2010 Deployment Tips
  2. 2. SharePoint 2010 Development with Visual Studio 2010  Intro: SharePoint Deployment…how Visual Studio 2010 affects what [and how] things are deployed to SharePoint  The Solution Package  Features  SPI’s  Properties, Properties, Properties: F4 is our Friend  The Solutions Package  Features  Visual Web Parts  Fixing the (default) Namespace Clutter  Replaceable Tokens Overview
  3. 3. SharePoint 2010 Development with Visual Studio 2010  Deployment ‘best practice’ Solutions & Features  Visual Studio 2010 supports SharePoint development natively  A Visual Studio SharePoint Project output is a SharePoint solution package (.wsp)  F5 for debugging  Right click to add things to the project  Features  SPI’s (or SharePoint Project Items) – SharePoint “objects” e.g. Content Types, Site Columns, Web Parts, Modules (files), List Definitions, List Instances etc. etc.  Supporting Files are deployed to the {SharePoint Root} (14 Hive) via mapped folders – /_layouts, /_layouts/images  The main problem? The project is by default very, very flat… Introduction
  4. 4. Properties, Properties, Properties
  5. 5. SharePoint 2010 Development with Visual Studio 2010  Properties (F4) – most items in the project have properties that control the final deployment  Solution (Visual Studio) – most important properties are on the Project. Won’t see the solution node unless there are multiple projects in the solution  Project  F4 – Sandbox Solution, Site URL, Assembly Deployment Type  ALT+ENTER – Default Namespace and other project properties  Solution Package – Id, Title  Feature – Id, Title, Deployment Path (Feature Folder Naming)  Web Part – Deployment Path  To control your deployment you must use the properties in Visual Studio Visual Studio 2010: Properties = Behavior
  6. 6. SharePoint 2010 Development with Visual Studio 2010  Sandboxed Solution  Site URL  Assembly Deployment Type Global vs. Web Application  … Project Properties
  7. 7. SharePoint 2010 Development with Visual Studio 2010  Name / Title  Solution Id  … Package (Solution) Properties
  8. 8. SharePoint 2010 Development with Visual Studio 2010  Deployment Path  Feature Id  Title [Connected to Feature Designer]  … Feature Properties $SharePoint.Project.FileNameWithoutExtension$_$SharePoint.Feature.FileNameWithoutExtension$
  9. 9. SharePoint 2010 Development with Visual Studio 2010  Deployment Location  … Web Part Properties
  10. 10. Fixing the (default) Namespace Clutter
  11. 11. SharePoint 2010 Development with Visual Studio 2010  Visual Studio’s ‘management’ of the namespaces related to your project are horrible  Namespaces cascade down (a little)  Solution Package (default namespace) + Web Part SPI (+ Web Part Class for the full strong name)  How do you control these? … Manually Namespaces
  12. 12. SharePoint 2010 Development with Visual Studio 2010 Add a New Web Part
  13. 13. SharePoint 2010 Development with Visual Studio 2010 Namespaces
  14. 14. SharePoint 2010 Development with Visual Studio 2010  Understanding folders and namespaces in Visual Studio 2010 SharePoint Solutions, Packages and Features http://www.wictorwilen.se/Post/Understanding-folders-and- namespaces-in-Visual-Studio-2010-SharePoint-Solutions-Packages- and-Features.aspx  Understanding folders and namespaces in Visual Studio 2010 SharePoint Solutions, Packages and Features - part 2 http://www.wictorwilen.se/Post/Understanding-folders-and- namespaces-in-Visual-Studio-2010-SharePoint-Solutions-Packages- and-Features-part-2.aspx Namespaces – References
  15. 15. Replaceable Tokens
  16. 16. SharePoint 2010 Development with Visual Studio 2010  Begin and end with a dollar sign ($). Any tokens used are replaced with actual values when a project is packaged into a SharePoint solution package (.wsp) file at deployment time.  Feature Naming  Strong Naming  Can/should/have to be used by you  By default used in: XML, ASCX, ASPX, Webpart, DWP  Defined in <TokenReplacementFileExtensions> element in the Microsoft.VisualStudio.SharePoint.targets *  Additional file extensions can be added – e.g. svc  Tokens only replaced in files that are not compiled – e.g. not used .cs, .vb or .resx.. Reference  Replaceable Parameters msdn.microsoft.com/en-us/library/ee231545.aspx  Nifty Trick http://www.wictorwilen.se/Post/Nifty-trick-with-Visual-Studio-2010-replaceable-parameters-for- SharePoint-2010-Web-Parts.aspx * …<program files>MSBuildMicrosoftVisualStudiov10.0SharePointTools Replaceable Tokens
  17. 17. SharePoint 2010 Development with Visual Studio 2010 Replaceable Tokens Name Description $SharePoint.Project.FileName$ The name of the containing project file, such as, "NewProj.csproj". $SharePoint.Project.FileNameWithoutExtension$ The name of the containing project file without the file name extension. For example, "NewProj". $SharePoint.Project.AssemblyFullName$ The display name (strong name) of the containing project’s output assembly. $SharePoint.Project.AssemblyFileName$ The name of the containing project’s output assembly. $SharePoint.Project.AssemblyFileNameWithoutExtension$ The name of the containing project’s output assembly, without the file name extension. $SharePoint.Project.AssemblyPublicKeyToken$ The public key token of the containing project’s output assembly, converted to a string. (16-characters in "x2" hexadecimal format.) $SharePoint.Package.Name$ The name of the containing package. … …
  18. 18. SharePoint 2010 Development with Visual Studio 2010  Can help to limit refactoring through less “hard coding”  GuidAttribute Replaceable Tokens using System.Runtime.InteropServices; namespace DemoProject.WebParts { [ToolboxItemAttribute(false)] [Guid("B7DB18AA-B8A7-4CD1-8389-03809D827EF0")] public class MyWebPart : WebPart { // ... } } <type name="$SharePoint.Type.b7db18aa-b8a7-4cd1-8389-03809d827ef0.FullName$, $SharePoint.Project.AssemblyFullName$" /> <type name="DemoProject.WebParts.MyWebPart, $SharePoint.Project.AssemblyFullName$" /> msdn.microsoft.com/en-us/library/system.runtime.interopservices.guidattribute.aspx
  19. 19. Questions
  20. 20. Resources
  21. 21. SharePoint 2010 Development with Visual Studio 2010  MSDN SharePoint Forums social.msdn.microsoft.com/Forums/en/category/sharepoint  SharePoint Overflow www.sharepointoverflow.com  SharePoint DevWiki www.sharepointdevwiki.com  SharePoint Team Blog blogs.msdn.com/b/sharepoint Community Forums and Helpful Sites
  22. 22. SharePoint 2010 Development with Visual Studio 2010  Channel 9 channel9.msdn.com/learn/courses/SharePoint2010Developer  SharePoint on TechNet technet.microsoft.com/en-us/sharepoint/  SharePoint Developer Centre msdn.microsoft.com/en-us/sharepoint/  SharePoint 2010 SDK msdn.microsoft.com/en-us/library/ee557253.aspx  Patterns and Practices spg.codeplex.com Technical Resources
  23. 23. Thank You

×