Wednesday, February 17, 2016

How to generate new Visual Studio Solution from existing solution?

Most of posts on Internet suggest to create a new solution and feature in Visual Studio, then copy/attach the files to the new project. (such as this one)

I find another opotion.

After copying the whole Visual Studio solution/project to new folder, there are 4 parts we need to replace.

1. DLL new key
2. Solution ID
3. Feature ID
4. Change the Solution name, Feature name, Assembly name (and webpart / workflow action name if needed).

The first two steps are easy. Open the project in Visual Studio, then do the change straight away.

But the third step is tricky: we cannot just go to "Feature Designer" and replace the GUID in "Feature Id" property.  This ID is used in 7 different places and we cannot change them all in Visual Studio.

I did that through the famous freeware "Notepad++", go to "Search", then "Find in Files"

Below is the search result after clicking "Find All" button.  We can click "Replace in Files" button to replace all old Feature Id with new GUID.

Step 4 is similar to step 3.

That's it.

Now we can compile and publish the new solution file (.wsp) in Visual Studio, and then deploy it SharePoint.


To use new solution and feature to replace old solution and feature in farm, don't forget to uninstall the old feature and solution first, if you don't want to change the solution name or feature name.

Below is the PowerShell script.

Get-SPSite -Limit ALL | ForEach-Object {Disable-SPFeature -identity "FeatureName" -URL $_.URL -confirm:$false -ErrorAction SilentlyContinue}

Get-SPFeature | ?{$_.DisplayName -eq "FeatureName"} | Uninstall-SPFeature -confirm:$false -force

Get-SPSolution | ?{$_.DisplayName -like "SolutionName"} | Remove-SPSolution -confirm:$false -force

You can go to SharePoint system folder "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions" on all SharePoint servers, then search for the feature name, to confirm the feature is removed from farm completely.

No comments:

Post a Comment