SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In one of my Visual Studio project, I have two javascript files (both deployed under Layouts):

  • Mywonderfulscript.js
  • Mywonderfulscript.min.js

The latter is the minified version of the former.

I would like to register either of the two depending on the build configuration.

By now I have this code inside my custom web control :

    protected ScriptLink scriptLinkRegistration;

    protected override void CreateChildControls()

        this.scriptLinkRegistration = new ScriptLink
            Localizable = false,
            Name = "pathto/Mywonderfulscript.js"
            Name = "pathto/Mywonderfulscript.min.js"

This is working, but this results in always deploying both files.

Is there any way to conditionally include a file into the resulting WSP file?

If the compilation configuration, include the full script, if not, include the minified script.

share|improve this question

As an alternative .. you could look at creatig the "Minified JS File" as part of your deployment / build scripts?

This could mean creating your own custom Deployment Configuration (well supported in VS2010 / VS2012).

Doing this you could create the WSP Package, then crack it open and replace the JS file with your new minified JS? (also updating the paths in any of the XML)

Then deploy your WSP using PowerShell?

share|improve this answer

I don't think this is possible without building your own custom Visual Studio extension.

Perhaps you could include a pre-build script which modifies the SPData file to remove the XML reference for your debug file?

You could then use a different script for DEBUG / RELEASE (or any other configurations) and this would also theoretically work in automated build environments too?

share|improve this answer
I'm not very fan of this technique, because modifying the spdata files will leads to source control issues – Steve B Apr 9 '13 at 10:04
Agreed .. maybe not suitable for a dev environment (although it would work for automated builds) – Martin Hatch Apr 10 '13 at 10:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.