3

I have created a Visual Studio 2012 solution for SharePoint 2013. In this solution there are 19 projects. In this solution there is some name from some customer. Now I would like to clone this visual studio solution. There is only 1 problem and thats the name of the original customer is used in the solution name, project names, namespace names, assembly names. Everywhere is using this name. What is the best practice to change these names?

See also the black marked lines. Here is used the name of the customer. I would like to rename it.

enter image description here

2

I recently have a similar requirement. I needed to rebrand a proof of concept into a well named product.

I wrote this script to handle most of the job:

$root = Get-Item C:\Projects\

$allFolders = Get-ChildItem $root -Recurse -Directory | Sort-Object FullName -Descending
$allFiles = Get-ChildItem $root -Recurse | ? { -Not $_.PSIsContainer}  | Sort-Object FullName -Descending

$from = "My.Old.Name"
$to = "My.New.Name"

foreach($file in $allFiles){

        $oldName= $file.FullName
        $newName = Join-Path (Split-Path $oldName) ($file.Name.Replace("$from", "$to"))
        $fileContent = Get-Content $file.FullName  -Encoding UTF8
        Write-Host "  " + $file.FullName.Replace($root,'')

        if($fileContent -match $from){
            $newContent = $fileContent | % { $_.Replace($from, $to) }
            Set-Content  -Path $oldName -Value $newContent -Encoding UTF8
        }

        if($oldName -ne $newName) {
            & "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe" move $oldName $newName
            #move $oldName $newName
        }

}

foreach($folder in $allFolders){

        $oldName= $folder.FullName
        $newName = Join-Path (Split-Path $oldName) ($folder.Name.Replace("$from", "$to"))


        Write-Host -ForegroundColor Green $folder.FullName.Replace($root,'')

        if($oldName -ne $newName) {
            & "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe" move $oldName $newName
            #move $oldName $newName
        }

}

The script will first grab all items (files and folders) under my projects parent folder.

Then, it will open all files and replace the old name to newname.

Next, the file names are renamed to match the new name (espcecially csprojet and sln files). Please note that I used TFS command line to rename the file, in order to maintain the source history. If you don't use TFS, either use a simple move or adapt to your VCSSC.

When all file contents and file names are updated, I reverse walked the folders. I mean by reverse walk that I sort by full path DESC to rename each folder one by one. If I don't sort in this way, I loose the subfolders from my previous exploration.

I also used TFS command line to rename the folder.

But here a few advises:

  1. BACKUP before running the script
  2. BACKUP
  3. backup
  4. before running the script, clean the solution. This will remove any bin, obj,pkg and pkgobj temp folders. You may have to clean some of this files manually. This is not a requirement, but if not, you'll risk to have some source control issue because theses files are not part of the project.
  5. I used UTF8 encoding to make my replacements. This worked for me, but double check files with international characters to see if the text is not altered.
  6. I used Visual Studio 2012 and TFS 2012 PowerTools. if you use another version of TFS, you will have to adapt the path to tf.exe

Finally, you should also be careful with exiting instances. You may collide ID's with previously deployed solutions. If you have to keep some instance of the old name somewhere, you should rewrite your solution and features IDS.

0

I have successfully renamed my solution as follow:

  1. Copy the solution and paste it in another folder.
  2. Open it in Visual Studio 2012
  3. Clean the solution
  4. Close Visual Studio 2012
  5. Open notepad ++ and open the function "replace in files"
  6. Browse to the folder where the clone solution exists
  7. Check the checkbox for subfolders
  8. Replace the old name into the new name
  9. Download some 3th party tool to replace a batch file names
  10. Also here browse to the folder of the clone solution
  11. check the checkbox of the subfolders
  12. Replace the old name into the new name
  13. Now you can open the solution in Visual Studio and should everything work fine
0

right click on your project(Example MyMVCProject.sln) and select "open with" option then to open in notepad++. In that file you can replace your old project name to new project name.

Example:

This is the MyMVCProject.sln file to open in notepad++

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyMVCProject"//////Hey this the name to change to NEW PROJECT NAME/////, "MyMVCProject\MyMVCProject.csproj", "{BE6429CB-F707-4E33-BCBC-EFDFD735CFAF}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {BE6429CB-F707-4E33-BCBC-EFDFD735CFAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {BE6429CB-F707-4E33-BCBC-EFDFD735CFAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {BE6429CB-F707-4E33-BCBC-EFDFD735CFAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {BE6429CB-F707-4E33-BCBC-EFDFD735CFAF}.Release|Any CPU.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
EndGlobal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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