SPClientSideDeployment 3.1 brings support for minified JS/CSS and seamless dev-prod transition

I have just released version 3.1 of SPClientSideDeployment with added support for minified JS/CSS. You are now able to include minified files in the deployment package that the tool generates, and instruct the generated PowerShell script to use them during deployment.

Download it now!

You can download the latest version of SPClientSideDeployment from the Visual Studio Gallery.

The challenge with minified files

A typical challenge when using minified files is that you’d only want to use them in production. In dev/test you typically want to continue using the unminified version for debugging purposes. The challenge is to have a mechanism that enables you to switch to using the minified version for production without having to change the source code of the consuming pages.

Seamless dev-prod transition with SPClientSideDeployment

SPClientSideDeployment addresses this challenge by enabling you to include both minified and unminified versions in the deployment package that it generates, and then specifying which version to use when executing the PowerShell deployment script (also generated by the tool – check out this post if you are not familiar with the package generation feature of SPClientSideDeployment).

Your consuming pages will always reference the same JS/CSS file names – e.g. script.js. The content of script.js will be minified or unminified depending on the parameter you provide when executing the deployment script. SPClientSideDeployment’s Visual Studio command continues to deploy the unminified version. This allows you to continue debugging while in development, and then seamlessly transition to minified versions when the solution is promoted to higher environments.


OK, let’s have a look at an example scenario.

Let say you have a page layout, ContentPageLayout.aspx, and that page references a stylesheet, styles.css. In Visual Studio you use LESS for the stylesheet. Your DeploymentSettings.xml file may appear as follow:

		<File localPath="styles.less">
				<Destination targetFolder="Style Library"/>

		<File localPath="ContentPageLayout.aspx">
				<Destination targetFolder="_catalogs/masterpage"/>
				<!-- Metadata required for the page layout omitted -->

You have installed the Web Compiler extension, and therefore styles.css and styles.min.css are automatically generated for you each time styles.less is changed.

During development you use various methods supported by SPClientSideDeployment, e.g. auto-deploy on save, to deploy the compiled output of styles.less to SharePoint. This will always deploy the unminified version, styles.css, to SharePoint.

Publish the package and include minified files

Now you are ready to promote the solution to a higher environment. Right-click the project in the Solution Explorer and choose SharePoint \ Publish Deployment Package. The dialog below appears after you have selected a publish location.

1 Publish Dialog

Tick the “Include minified files if available” option and click OK. This option creates a “__minified” sub-folder under the selected publish location and copies the minified version of all files referenced in DeploymentSettings.xml to this sub-folder (if they are found). The unminified versions are always included in the package.

If you had selected F:\Test as the publish location, the published package would contain the following:

  • F:\Test\ContentPageLayout.aspx
  • F:\Test\styles.css
  • F:\Test\__minified\styles.min.css
  • [other files omitted]

Execute the deployment script and specify to use minified files

The published package includes a generated PowerShell file, namely DeployFiles.ps1. To execute the deployment using the minified files, include the -UseMinifiedFiles switch parameter. For example:

.\DeployFiles.ps1 -DeploymentSettingsFilePath .\DeploymentSettings.xml -SiteUrl http://myServer -AuthenticationMethod Windows -UseMinifiedFiles

Check this post for other parameters that can be specified.

When the script encounters style.less in the DeploymentSettings.xml, it will take the file F:\Test\__minified\styles.min.css and upload that to SharePoint as styles.css. If the -UseMinifiedFiles switch was not specified, the script would use the file F:\Test\styles.css instead. Since in either case the target file name will be the same, styles.css, no source code changes to the consuming page are required.

Does SPClientSideDeployment perform the minification?

No. The tool is only responsible for including the minified files in the package that it generates and allowing you to use them as part of the deployment. You must use other tools to perform the minification. You can use the Web Compiler extension to do this for example if you are working with JSX, LESS or SASS.

How does SPClientSideDeployment locate the minified files?

When the tool encounters a ‘minifiable’ file, i.e. with .js or .css extension, it looks for the minified version in the same physical location as the unminified version. The file name of the minified version must correspond to that of the unminified version, e.g. scripts.min.js for scripts.js, styles.min.css for styles.css.

What about ‘compilable’ files such as JSX, LESS or SASS?

SPClientSideDeployment supports JSX, LESS and SASS – and this includes minified compiled output. When a compilable item is encountered in the DeploymentSettings.xml, e.g. form.jsx, the tool first looks for the associated compiled output, which in this case would be form.js. The tool then look for a minified version of this output, i.e. form.min.js. Both form.js and form.min.js would then be included in the generated package and processed in the same manner as other minifiable files.

What if my solution uses a mixture of minified and unminified files?

When publishing the package, the tool simply ignores any minified file that it could not find.

When executing the deployment, if the -UseMinifiedFiles switch is specified but a minified version is not available for a minifiable file, then the tool will fallback to using the unminified version for that particular file. A warning will be generated in this case.

What if my solution uses a minified library such as jquery?

If your DeploymentSettings.xml file references minified libraries, such as jquery_1.10.2.min.js, then these are treated as ‘non-minifiable’ and they will be processed in the same way as other non-JS/CSS files. This means the tool will not look for a minified version.

In my DeploymentSetttings.xml file, do I need to explicitly reference each minifiable file?

No. You can explicitly reference the minifiable file using the File element, or use folder-based declaration using the Folder element. When processing a referenced folder, the tool will look for minified version of any minifiable file within that folder and its sub-folders.


This release of SPClientSideDeployment aims to streamline your process in developing with minifiable files and transitioning from dev to production. I hope you find it useful – and as always, would love to hear from you with feedback and suggestion.


Posted in SharePoint, SharePoint 2013, SPClientSideDeployment | Leave a comment

Setting HTML content for Content Editor Web Part by code

To set the content of a Content Editor Web Part (CEWP) by code you need to set the Content property of the ContentEditorWebPart class. There is an example of how to do this in the aforementioned MSDN link.

There is however a small trick required if you want to set the content to HTML, e.g. <b>Hello world!</b>.

The trick is to wrap the content of the XML node in a CDATA section. Below is the modified example from MSDN to do this:

// Create a new Content Editor Web Part.
ContentEditorWebPart ceWebPart = new ContentEditorWebPart();

// Create an XmlElement to hold the value of the Content property.
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlElement = xmlDoc.CreateElement("MyElement");

// Wrap content in CDATA section if it contains HTML
xmlElement.InnerText = "<![CDATA[<b>Hello world!</b>]]>";

// Set the Content property to the XmlElement.
ceWebPart.Content = xmlElement;
Posted in SharePoint | Leave a comment

SPClientSideDeployment 3.0 adds auto-deploy on save option and support for compilable JS and CSS

I have just released version 3.0 of SPClientSideDeployment with two major enhancements:

  • Auto-deploy on save: when this option is enabled, files will automatically be deployed to SharePoint each time you save them
  • Support for compilable JavaScript and CSS: the tool detects if the file is TypeScript, JSX, LESS or SASS, and if so deploys the compiled output to SharePoint

Download it now!

You can download the latest version of SPClientSideDeployment from the Visual Studio Gallery.

Auto-deploy on save

When this option is enabled, files configured for deployment in DeploymentSettings.xml will be automatically deployed to SharePoint each time they are saved.

To enable this option go to Tools \ Options \ SPClientSideDeployment and set Automatically Deploy on Save to true.

1 Option Menu

Note that this option does not report any error if the file you are saving is not defined in DeploymentSettings.xml. If a file is not being deployed on save as you had expected, then check if the file is correctly configured in DeploymentSettings.xml by explicitly triggering a deployment for the file (i.e. right-click then Deploy to SharePoint).

Support for compilable JavaScript and CSS

You can now specify TypeScript, JSX, LESS and SASS items in DeploymentSettings.xml for deployment. When the tool encounters one of these file types, it will look for and deploy the corresponding compiled output file instead of the actual source file.

For example, if the following was specified in DeploymentSettings.xml:

<File localPath="Scripts.ts">
		<Destination targetFolder="Style Library" />

then the tool will look for the file Scripts.js and deploy that to the Style Library. 

“Compilable” items are also supported when the Folder element is used in DeploymentSettings.xml. When processing files in the specified folder, the tool would look for and deploy the corresponding compiled outputs for any detected compilable items. Non-compilable items are processed as normal.

How compiled outputs are inferred

The tool always looks for the compiled output in the same physical location as the source file. The file name of the compiled output is inferred from the file name of the source file.

  • TypeScript source file: example.ts   –   compiled output: example.js
  • JSX source file: example.jsx   –   compiled output: example.js
  • LESS source file: example.less   –   compiled output: example.css
  • SASS source file: example.scss   –   compiled output: example.css

Automatic compilation of compilable JavaScript and CSS

The tool only looks for and deploys the compiled outputs of compilable items. It does not perform any compilation. The tool works best when automatic compilation of these items are enabled in Visual Studio.

For TypeScript, automatic compilation is supported in Visual Studio 2015. By default this is only available for ASP.NET Web Application projects. See this post for enabling it on other project types.

For JSX, LESS and SASS, you can use the Web Compiler extension to enable this.

SPClientSideDeployment’s option to automatically deploy on save works nicely with automatic compilation. If you have enabled this option, then the tool will monitor and automatically deploy the compiled outputs after the compilation has finished.

How compilable items are treated when publishing deployment package

SPClientSideDeployment has a feature that allows you to publish your project as a package for deployment. The package includes a PowerShell script that you can use to deploy the files to a target SharePoint instance. I encourage you to read more about this feature here if you are not already familiar with it.

Support for compilable items has also been added to this feature. When publishing a package, if a compilable item is detected, then only its compiled output would be included in the package. The generated PowerShell script would correctly deploy the compiled outputs to the target SharePoint instance.

Note that the PowerShell script has been updated to include this support. Therefore, if you are updating an existing project to take advantage of this feature, then you’d need to republish the package to regenerate the PowerShell script.

Support for minified version of compiled outputs

Currently there are no supports for minified version of the compiled outputs. This will be added in the next version.


This release aims to further streamline your dev-deploy-test-repeat process and enables you to extend this streamlined approach to compilable JavaScript and CSS. I hope you find the new features useful – and as always, would love to hear from you with feedback and suggestion.


Posted in SharePoint, SPClientSideDeployment | Leave a comment

Enabling native TypeScript support in other project types in Visual Studio 2015

Native TypeScript support in Visual Studio 2015 is not available for all project types by default. As far as I’m aware, it is only available for the ASP.NET Web Application project type.

Sometime, you may be working with TypeScript but would prefer to use a different project type, e.g. when you are working with CRM or SharePoint. To add native TypeScript support to a project type of your choice, add the following to the project file:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" />

Reload your project, go to the project’s properties in Visual Studio and you should now see the TypeScript Build tab.

Posted in CRM, JavaScript, SharePoint | Leave a comment

How to hide custom sub-grid ribbon button in Advanced Find results [CRM]

With RibbonDiff you can add a custom button to the ribbon of a sub-grid. You can further add a display rule to only show this button when the sub-grid is being shown within the form of a particular parent entity type. This is achieved by the FormEntityContextRule. Below is an example RibbonDiff XML to add the “Click Me!!” button and to have it shown only when the sub-grid is being displayed on the new_staff form.

		<CustomAction Id="new.new_staff.Test1.CustomAction" Location="Mscrm.SubGrid.new_staff.MainTab.Management.Controls._children" Sequence="1">
				<Button Id="new.new_staff.Test1.Button" Command="new.new_staff.Test1.Command" Image32by32="/_imgs/Ribbon/Entity32_8006.png" Image16by16="/_imgs/Ribbon/Entity16_8006.png" LabelText="Click Me!!" Sequence="1" TemplateAlias="o1"/>
		<CommandDefinition Id="new.new_staff.Test1.Command">
				<DisplayRule Id="new.new_staff.DisplayRule.StaffFormOnly"/>
				<JavaScriptFunction FunctionName="isNaN" Library="$webresource:new_staff/staff.js"/>
			<DisplayRule Id="new.new_staff.DisplayRule.StaffFormOnly">
				<FormEntityContextRule EntityName="new_staff"/>

By default however this button would then also be shown in Advanced Find results. This is because Advanced Find results is essentially treated as a sub-grid.

Sub-grid on the Staff form:

1 Sub-Grid on Form

Advanced Find results:

2 Advanced Find

To hide the button in Advanced Find results, we need to add the Default=”false” attribute to the FormEntityContextRule as below.

<FormEntityContextRule EntityName="new_staff" Default="false"/>

By the way, check out CRMQuickDeploy if you are a CRM ninja that works with RibbonDiff XML directly in Visual Studio and wants to quickly deploy it to CRM.

Posted in CRM | Leave a comment

New version of SPClientSideDeployment adds support for folder-based file deployment and automatic folder creation

I have just released version 2.0 of SPClientSideDeployment with two major enhancements:

  • Folder-based file deployment – this allows you to define a local folder in the DeploymentSettings.xml file. All files under this folder (and its sub-folders) will be processed by the tool.
  • Automatic folder creation – all folders on the target path will now be automatically created by the Visual Studio command.

Download it now!

You can download the latest version of SPClientSideDeployment from the Visual Studio Gallery.

Folder-based file deployment

In previous versions, each file to be deployed needed to be declared individually in the DeploymentSettings.xml file. This can be cumbersome for large projects. In this release you can now use the Folder element to define a local folder to be deployed to SharePoint. All files under this folder (and all of its sub-folders) will be processed by the tool. The schema for this new element is very similar to the File element. Review the inline comment below for more details.

<?xml version="1.0" encoding="utf-8" ?>
		<!-- Define local items to be deployed by using a combination of File and Folder elements. -->
		<File localPath="Script1.js">
		<File localPath="Script2.js">

		<!-- localPath: Required. Local path of the folder to deploy. Relative to the current project. Value should not start with '/'. Files within this folder and all of its sub-folders will be processed. -->
		<Folder localPath="Scripts">
				<!-- Same usage as Destination element for File. targetFileName is not supported when this element is being used for Folder. All files in the local folder will be deployed to the target location using the local file name. The local sub-folder structure will be automatically re-created at the target location. -->
				<Destination targetWeb="" targetFolder="Style Library"/>
			<!-- Same usage as Metadata element for File. The same metadata will be applied to all files within this folder. -->
				<Field name="ContentTypeId" value="0x01010007FF3057"/>

The sub-folder structure of the defined local folder will be automatically re-created at the target location. For example, given the Scripts folder and its content below:



and the definition in the DeploymentSettings.xml file:

		<Folder localPath="Scripts">
				<Destination targetFolder="Style Library/Intranet"/>

The file utility.js will be deployed to the Style Library, under the Intranet folder. The file search.js will be deployed to the Style Library, under the Intranet/Search folder. The Intranet folder under the Style Library and its Search sub-folder will be created automatically.

Remember to republish your deployment package if you are planning to update your existing DeploymentSettings.xml to use the new Folder element. This is because the DeployFiles.ps1 has been updated to support the new element.

Automatic folder creation

In previous versions, all folders on the target deployment path (specified via the targetFolder attribute) must exist at the target location when using the Visual Studio command. This however was not a requirement when using the PowerShell deployment script generated by the tool (as the script automatically creates any non-existing folder). This release brings the same capability to the Visual Studio command. Any non-existing folder at the target location will now be created automatically by the Visual Studio command, in the same manner as the PowerShell deployment script.


This release brings two major enhancements that aim to simplify your deployment configuration. I hope you find them useful – and as always, would love to hear from you with feedback and suggestion.


Posted in SharePoint, SPClientSideDeployment | 1 Comment

CRMQuickDeploy 2.6 adds RibbonDiff deployment from Visual Studio

Rather than storing the ZIP solution in source control, some project teams choose to store the source code of each individual component instead, for example by using the SolutionPackager tool. This allow team members to easily track changes to components at check-in, or to understand how a component was changed over time.

One type of component that may be stored in source control in this way is the RibbonDiff XML for entities. The process of modifying and deploying RibbonDiff is pretty cumbersome though. Natively it involves exporting a solution, modifying the XML and reimporting the solution. The popular Ribbon Workbench automates this process and provides a great UI for editing the XML, but it is rather slow for making small changes – and it also does not help in storing the source code for the RibbonDiff.

CRMQuickDeploy 2.6 adds a feature that allows you to quickly deploy RibbonDiff XML from Visual Studio to CRM for an entity.

1 Deploy Ribbon (1)

Download it now!

You can download the latest version of CRMQuickDeploy from the Visual Studio Gallery.

Accessing the command

This command is accessible by right-clicking on the code editor of the RibbonDiff.xml file, or by the Alt+Q, F shortcut key.

2 Context Menu

Note that this is the same command for deploying web resource. The command determines the current file in the code editor to be a RibbonDiff if its file name is RibbonDiff.xml, and if it is not located under the WebResources folder of the project.

Therefore, to use this command for RibbonDiff deployment, ensure that:

  • The file is named RibbonDiff.xml
  • The file is not located under the WebResources folder of the project, or one of its sub-folders
  • The file is contained in an immediate folder with the name of the target entity (see below)

Specifying target entity for RibbonDiff

The RibbonDiff schema does not contain information about the target entity. The command therefore uses the name of the immediate parent folder of the RibbonDiff file to determine the target entity. If the target entity is new_staff for example, place the RibbonDiff file for this entity directly under a folder named new_staff.

Posted in CRM, CRMQuickDeploy | Leave a comment