If you know me by now, you know that I’m a lazy man. I’ll spend 3 hours trying to find a better way to do work that would only take me 1/2 an hour if I just sat down and did it. Hmmm… maybe I’m not lazy, maybe I’m just determined. Yeah… that probably sounds better on a resume… so.. if you know me by now, you know I’m a determined man… if I think there should be a better way to do something, I’ll find it. See… that sounds so much better than lazy…
So, here was my current problem. I downloaded a WSP file (SharePoint Solution File for you lay persons). It’s not important what the WSP did… It did something I needed it to do.. okay? Anyway, I deployed the WSP… the skies opened up… sun shined… sun shown… sun rays fell from the sky… angels sang… life was good…
Or was it? Ugh.. I did not like that one view… it only showed 5 items in a list at a time (and I had 20,000 items to view). However, this wasn’t just a view on a list so I couldn’t edit the page, or modify the view. Again, don’t worry about why I couldn’t do that. I just couldn’t… okay? The angels shut up.. clouds covered the sky.. blah.. blah.. blah…
So, this stinkin view that I couldn’t edit in SharePoint or SPD only showed 5 rows at a time and I need to browse through 20,000 entries? That’s a show stopper right there…. or was it?
So.. brilliant idea… lets crack open the WSP file, modify the view (it was just an ASPX page) and redeploy the Solution? Sounds rockin right? Okay… not so fast. If you have ever tried to extract a file from a WSP you’ve found it’s super easy. However, if you’ve ever tried to add the file back to the WSP (or CAB) you soon realize it’s not possible.
Worse yet, if you just rename a WSP file to CAB so that you can explore it in Windows I don’t think there is a way to extract out the directory structure. So, I’m left with a mess. If I want modify a file in a WSP file I have to follow these steps:
- Rename WSP file to CAB and extract all the files
- Modify the necessary files
- Rebuild the correct directory structure for the solution
- Copy the files into that directory structure (in the right place)
- Create a DDF file indicating name and location of all files to be in WSP file
- Run MakeCab using created DDF file to create cab, then rename cab to WSP
Sound about right? None of that is too difficult, it just sounds like a lot of garbage to go through when all I want to do is modify ONE stinking little file and re-deploy. So, I posted the question on Twitter and started quite the discussion. From all the responses I was actually able to put together a very quick method for extracting and rebuilding WSP files. (Thanks to @ChrisO_Brien, @davidfrette, @coreyroth, @tigertoy, @rhabridge, @RemyMaza, @BrianTJackett, @sympmarc, and @SharePoint Ninja for the discussion and Help). So, would you like to know the solution??? Hear it goes…
1. Extract WSP using 7 Zip
7 Zip is a free tool that will allow you to extract your WSP files AND the directory structure it was built with. There are probably other zip tools that will do this as well, I was just not able to do it with Windows. Regardless, use a tool that let’s you extract the files and directory structure from the WSP file.
2. Modify your files
Okay, now go in and modify the files you need to modify. Make whatever changes you need to make. Be VERY careful if messing with the XML files though…all kinds of nastiness there if you screw something up.
3. Download and use DDFGenerator from CodePlex
So, my new friend on Twitter @tigertoy pointed me to a project on CodePlex called DDFGenerator. It’s simply an executable. All you have to do is download this executable, execute it from the command line and give it the Path to the directory structure created by 7 Zip (or whatever program you used). This will generate your DDF file for you.
One quick note, the DDF Generator does not put an entry in the DDF to set the WSP file name. So, make your life easier, open up the .DDF file and add the following line along with the ther .Set lines:
This will make sure your WSP file is named properly with the correct extension. If you don’t do this it will create a cab file called “1.cab” when you run MakeCab.exe in the next step and you will have to rename it to your solution name. Not a big deal, just something to keep in mind.
4. Run MakeCab to create .CAB File
Now all you have to do is run MakeCab to generate your WSP file using the DDF you generated. This also will be run from the command line and will look something like:
After you run the above command, you will have your WSP file which you can go deploy… watch the skies open again… yadda.. yadda.. yadda…
Thanks again for all those who helped with this today. Even though it is a four step process, it is a very QUICK four step process. By far the easiest solution I have found so far. That does NOT mean there is not a better one.. if you have one, I’d love to hear it.