6

I've been provided a WSP file that contains a webpart created by another developer. I have been requested to make modifications to the webpart and repackage as a WSP file again.

What steps must be taken to import the contents of my WSP file into Visual Studio for modifications and repackaging?

Thanks much for your help.

7 Answers 7

7

As far as I know, you can only open the wsp file as a cab and modify the files from there. The downside is that all the code will be compiled into assemblies and there will be no way to extract the code from them.

You could create a new Visual Studio web part project and add the assemblies from the wsp file and see if there are any open facing classes or members that can be accessed and go from there.

Check here for more info on how to extract files from the wsp file:

http://sharepointroot.com/2010/07/07/editing-contents-of-a-wsp-sharepoint/

9
  • 3
    Make sure in Folder Options of windows explorer you have the "Hide extensions of known file types" unchecked before renaming. Commented Apr 4, 2012 at 23:45
  • 1
    You could use a tool like the .Net Reflector to decompile and look at the code.
    – Ian
    Commented Apr 5, 2012 at 8:14
  • 2
    No offence SidC but if you're struggling to rename a file how do you expect to be able to carry out the 'modifications' whatever they may be?
    – Ryan
    Commented Apr 5, 2012 at 10:18
  • 1
    You need to add that other project with the classes to your solution and add that project to your Reference list of your solution. Or just copy and paste them in your current solution. Commented Apr 5, 2012 at 17:47
  • 1
    I don't believe it does, unless there is another PublicKeyToken with the same value. If you found my response or comments helpful, would you mind upvoting them or selecting it as the correct answer :) Thanks. Commented Apr 5, 2012 at 18:57
3

You cannot simply 'repackage' a WSP, it must be rebuilt. Rename the file from .wsp to .cab and then double-click on it and you should be able to extract everything out of it. Then create a new SharePoint project in Visual Studio and add the items from the cab to the project. The complexity of setting up the new VS project will depend on the complexity of the WSP.

Neither the original source code nor the original VS Project/Solution exists in the WSP.

The best approach is to make every effort to get the original Visual Studio solution and source code from the developer. This is especially true if the changes you need to make to the webpart involve code changes. Not only is the source not in the WSP, but the code was most likely signed with a key you do not have access to, which means that even if you use a tool like Reflector to get the source, you cannot rebuild the library using the original strong name.

This means that every instance of the current webpart in SharePoint will continue to point to the original DLL, regardless of your changes. If you delete the original DLL, all of those webparts will then break.

If you are doing code changes and do not have access to the original project and source, it is very likely that you will have to manually replace every instance of the webpart with the one that refers to your new library.

3
  • Is the rename from .wsp to .cab done via Windows Explorer or via Command line?
    – SidC
    Commented Apr 4, 2012 at 23:30
  • Either way works so use whatever you are comfortable with. If you use Explorer, you might need to uncheck the 'Hide known extensions' box in the Folder Properties dialog.
    – Dave Wise
    Commented Apr 4, 2012 at 23:56
  • 1
    Visual studio 2010 allows you to import the WSP using the project template "Import SharePoint Solution Package" so you can skip the rename part, but you shouldn't do that unless the original source code has been lost. Commented Apr 5, 2012 at 9:57
2

In order to modify the content of wsp file first you have to unpack it and after necessary changes repack it again.
And in order to do that you need to use some third party tool like this one(download it from end of post, WSPCompression.zip) password of zip file is: www.itnerd.ir
extract or unpack wsp files and vise versa

2
  • 1
    @ShardaSIngh glad to helped you, but you can vote up my post too. Commented Dec 3, 2013 at 19:59
  • This tool is great! Still works!!
    – Aaronster
    Commented Jul 4, 2014 at 15:27
1

When changing a .wsp to a .cab file, the structure is lost in translation and cannot be recompiled back to a functioning .wsp. Using WSPBuilder from codeplex (http://wspbuilder.codeplex.com/) you can extract the .wsp, modify any contents (.aspx, .xml, .ascx, .master, etc.) besides the DLLs without using Visual Studio and repackage back into a .wsp. You can find detailed instructions on the commands to run from the command prompt at: http://www.itmonotony.com/Lists/Posts/Post.aspx?ID=40

1
  • link not working
    – Preeti
    Commented Feb 2, 2021 at 14:50
0

you can only change the files present in the WSP. you cannot change the code behind. (there is a workaround for webparts/application pages)

download the following : CABSDK from microsoft. There you need 2 EXE's

  1. CABARC.exe
  2. EXTRACT.exe

Process:

  1. use the 2nd exe to extract the WSP to a folder.
  2. change the files.
  3. If you want to change the code for application pages/web parts/user controls, then just add the script runat'server' in the aspx/ascx
  4. use the CABARC.exe to zip it back to WSP extension.
  5. Deploy it..... hurray

1
0

Another solution if you use Total Commander (or Unreal Commander) file manager you can setup WSPPacker plugIn and edit/pack/unpack WSP/CAB files seamlessly.

0
  1. Download Telerik Just Decomplier from here http://www.telerik.com/products/decompiler.aspx
  2. Copy the WSP and change one of the copies WSP extension a CAB extension.
  3. Copy all of the files to a directory.
  4. Decompile the Dll and save it to a project.
  5. In visual studio 2013 ultimate create a new sharepoint project from an existing project and use the unchanged package to create the objects.
  6. From the two projects you will have every thing you need to rewrite the package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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