Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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,
#if DEBUG
            Name = "pathto/Mywonderfulscript.js"
#else
            Name = "pathto/Mywonderfulscript.min.js"
#endif
        };
        this.Controls.Add(this.scriptLinkRegistration);
     }

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
add comment

2 Answers 2

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
add comment

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
add comment

Your Answer

 
discard

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.