Building SharePoint 2010 Customisations with Visual Studio 2010: Overview and Tips
-
Upload
nick-hadlee -
Category
Education
-
view
3.018 -
download
0
description
Transcript of Building SharePoint 2010 Customisations with Visual Studio 2010: Overview and Tips
Nick Hadlee @nickhadlee http://hadlee.net.nz
SharePoint Development: Visual Studio 2010 Deployment Tips
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
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
Properties, Properties, Properties
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
SharePoint 2010 Development with Visual Studio 2010
Sandboxed Solution
Site URL
Assembly Deployment Type Global vs. Web Application
…
Project Properties
SharePoint 2010 Development with Visual Studio 2010
Name / Title
Solution Id
…
Package (Solution) Properties
SharePoint 2010 Development with Visual Studio 2010
Deployment Path
Feature Id
Title [Connected to Feature Designer]
…
Feature Properties $SharePoint.Project.FileNameWithoutExtension$_$SharePoint.Feature.FileNameWithoutExtension$
SharePoint 2010 Development with Visual Studio 2010
Deployment Location
…
Web Part Properties
Fixing the (default) Namespace Clutter
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
SharePoint 2010 Development with Visual Studio 2010
Add a New Web Part
SharePoint 2010 Development with Visual Studio 2010
Namespaces
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
Replaceable Tokens
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>\MSBuild\Microsoft\VisualStudio\v10.0\SharePointTools
Replaceable Tokens
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.
… …
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
Questions
Resources
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
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
Thank You