- New in 3.3: Added option to publish on deployment
- New in 3.2: Added support for deploying assemblies to GAC (On-Prem only)
- New in 3.1: Added support for minified JS/CSS and seamless dev-prod transitioning
- New in 3.0: Auto-deploy on save option and support for TypeScript, JSX, LESS and SASS
- New in 2.0: Added folder-based file deployment and automatic folder creation
- New in 1.2: Added context menu to files and folders in Solution Explorer
- New in 1.1: Generate deployment package and PowerShell script for your project
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!
Download it now!
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.
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:
- 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.
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.
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.
Then chooses Yes in the dialog that appears.
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.
- 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.
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.
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.