SPClientSideDeployment: a new productivity Visual Studio extension for SharePoint developers

I have released a new Visual Studio extension that allows you to deploy files from within Visual Studio to SharePoint using CSOM. This extension works with both SharePoint On-Prem (local or remote server) and SharePoint Online, and on any C#, VB.NET or SharePoint project template. Keyboard shortcuts are included to maximise your productivity!

1 Demo

Download it now!

Download from Visual Studio Gallery

Getting started – specifying your target site

Three properties are added to the property grid for a project. These are SharePoint URL, Authentication Method, and User Name.

2 Properties

Specify the URL of the target site collection or sub-web in the SharePoint URL property. Deployable files within the project will be deployed to locations underneath this URL.

SharePoint project templates already have a Site URL property OOTB, and this is reused by the extension. For these project templates, only the Authentication Method and User Name properties will be available.

Choosing your authentication method

The extension supports the following authentication methods:

3 Authentication Methods

  • Windows (integrated authentication): set the Authentication Method to Windows and do not specify a user name.
  • Windows (user name and password): set the Authentication Method to Windows and specify a user name.
  • Form: set the Authentication Method to Form and specify a user name.
  • SharePoint Online: set the Authentication Method to SharePointOnline and specify a user name.

Entering your password for deployment

Except for Windows integrated authentication, all other methods prompt you to enter a password when you first execute the deployment for a given project.

4 Password Prompt

The password is cached in memory for the project and is never written to file. The cache is clear when the solution is closed.

Configuring the deployment

Each project requires a deployment settings file. This file should be named DeploymentSettings.xml and should sit at the root of the project. This file defines which files in the project will be deployed, their target locations, and the metadata to apply in SharePoint.

5 Deployment Settings File

The extension can create a skeleton deployment settings file for you if one does not already exist in the project. Right click the project in the Solution Explorer and choose SharePoint \ Deploy Files.

6 Project Menu

Then chooses Yes in the dialog that appears.

7 Create Prompt

This creates a skeleton file as below. Please review the comments in the file, which explain the schema.

<?xml version="1.0" encoding="utf-8" ?>
<DeploymentSettings>
	<Files>
		<!-- 
			localPath:	Required. Local path of the file to deploy. Relative to the current project. Value should not start with '/'. For link items, specify
						the localPath relative to the current project as if the item is a normal item.						
		-->
		<File localPath="Script1.js">
			<!-- Multiple destinations per local file are supported. -->
			<Destinations>
				<!--
					targetWeb:			Optional. Relative to the deployment URL setting specified for the current project. If not specified, then the web at the URL setting will
										be used. Value should not start with '/'. 										
					targetFolder:		Required. Relative to targetWeb. Value should not start with '/'. Use this to target a library, or a folder/sub-folder within a library.
										The specified path must already exist at the target web. Here are some examples: 
										
											_catalogs/masterpage/display templates/content web parts
											Style Library/MyPortal/CSS/Mobile
											
					targetFileName:		Optional. The file name that will be used at the target location. If not specified, the local file name will be used.
				-->
				<Destination targetWeb="" targetFolder="Style Library" targetFileName="script1.js"/>
			</Destinations>
			
			<!-- Optional. -->
			<Metadata>
				<!--
					name:				Required. Internal name of the field to set. 
					value:				Required. Value for the field to set. 
				-->
				<Field name="Title" value="Script 1"/>
				
				<!-- Multiple fields are supported. -->
			</Metadata>
		</File>
	</Files>
</DeploymentSettings>

The deployment settings file is automatically kept in sync when you delete or rename a file in the project.

Kicking off the deployment

There are a couple of ways to kick off a deployment.

  • Alt + Q, F: Starts deployment for the solution’s StartUp project. All deployable items within this project will be deployed. This can also be accessed from Tools \ SharePoint Deployment \ Deploy Files.8 Menu
  • Right click a project in the Solution Explorer and choose SharePoint \ Deploy Files. This will deploy all deployable items within this project.
  • Alt + Q, D in the code editor window. This will deploy only the current item. This can also be triggered by clicking Deploy to SharePoint from the editor’s context menu. Note that this command is not available for .CS or .VB files.9 Context Menu

Handling of check-in and check-out

The extension always attempts to check-in the file after it has been deployed. If minor version is enabled at the target location, then the file will be check-in as a minor version.

If a file needs to be updated, the extension attempts to check-out the file (if it is not currently checked out to the user). The file will be check-in after it has been updated (if it was check-out by the extension prior to the update). A comment is recorded in the version history for each update.

10 Version History

A note on SharePoint Online

To deploy to SharePoint Online, ensure that scripting is enabled for your tenant. Please refer to this article for more details.

That’s it! I hope you will find this tool useful and an improvement to your productivity – and I’d love to hear from you with feedback and suggestions.

About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.
This entry was posted in SharePoint 2013, SPClientSideDeployment. Bookmark the permalink.

14 Responses to SPClientSideDeployment: a new productivity Visual Studio extension for SharePoint developers

  1. I’m trying to deploy all files in my Scripts folder (in my VS project) to Style Library/Scripts. Can you provide a sample config to do this as I can’t seem to get the paths right.

  2. Ofer Gal says:

    What project template should I start with? Your add on does not supply one.

    • Bernado says:

      Hi Ofer,

      This extension works with the C# or SharePoint project templates that come with Visual Studio. If your project contains only files to be uploaded to SharePoint then I’d just use the standard C# Class Library project (and delete any class file). If your project contains a mixture of files to be uploaded and other SharePoint-specific elements (e.g. features, content types, etc.) then I’d use one of the SharePoint project templates.

      Note that if a SharePoint project template is used, then the extension uses the site URL setting that comes with the SharePoint project template.

  3. Serge Wazuki says:

    Thanks for this extension, it really helped me a lot! Could you please add support for wildcards (e.g: “*”) in next version so that it will deploy all files (or specific files) under the folder. It will save time instead of adding individual section for each file.

    Thanks a lot again! 🙂

  4. Ofer Gal says:

    Works like a charm.
    Here is an Idea for enhancement. Make it work when I hit F5 so I can start right away 🙂

  5. Thomas says:

    Thanks for Publishing this extension. It’s really helpful.
    I have an issue when deploying to german SharePoint installation. In SharePointManager.TryGetFile() the exception message is checked by StartsWith(“File Not Found”). This fails on a non-english SharePoint (e.g. in german the massage says “Datei nicht gefunden”. Could you please change the check to
    if (serverException.ServerErrorTypeName != “System.IO.FileNotFoundException”) { }

Leave a comment