问题
Hello I have setup visual studio express c++ project, with paths to included headers and libs Now I like to duplicate this project to be with the same paths to included headers and libs But with different name , I don’t what to go manually into .vcproj file and start to changes names Is there better way?
回答1:
Probably the easiest and fastest way of doing this is using Windows Explorer to just make a copy of the entire project. You will most likely need to assign the copied .vcproj file a new, unique GUID. To do this, open the file in Notepad and paste in a new ProjectGUID
from guidgen.exe
or similar application. Once you've done that, you can simply open the duplicate project in Visual Studio and re-name it.
Alternatively, you could try something like CopyWiz (although I've never used it, there is a free trial available to see if it works for you).
Unless you're trying to create a template for new projects, in which case there is a better way.
回答2:
Wrote this which works for me if run in Powershell (supplied with Win 7 and others) Even if it does not work correctly for you, it may be a good starting point.
# set the initial values.
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[Windows.Forms.MessageBox]::Show(“This script assumes that each project lives in a directory with the same name as the project, as VC defaults to. Input a) the directory holding both the existing project and the new project. This is the directory CONTAINING the directory with the name of the existing project. It must include the final backslash. b) the name of the existing project. c) the name of the new project”, “”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
($myroot=(Read-Host "Enter path of directory holding new and existing projects."))
($projectname=(Read-Host "Enter the name of the project to copy. Must be a single word"))
($newname=(Read-Host "Enter the name of the new project. Must be a single word"))
# make a copy of the original
Set-Location $myroot
Copy-Item "$myroot$projectname" "$myroot$newname" -recurse
# find and rename all files containing the original project name
# run without recurse first or an error occurs
Get-ChildItem $myroot$newname\ -force| Where-Object {$_.name -like "*$projectname*"}| rename-item -newname { $_.name -replace "$projectname","$newname" }
Get-ChildItem $myroot$newname\ -force -recurse| Where-Object {$_.name -like "*$projectname*"}| rename-item -newname { $_.name -replace "$projectname","$newname" }
# find all references within the code to the projectname and change those
Set-Location $myroot$newname
Get-ChildItem -recurse | where {$_.extension -eq ".cpp"-or $_.extension -eq ".h" -or $_.extension -eq ".sln" -or $_.extension -eq ".vcxproj" -or $_.extension -eq ".rc"} `
|foreach-object {(get-content $_.fullname) | foreach-object {$_ -replace "$projectname", "$newname"} | set-content $_.fullname}
# delete sdf and suo files
remove-item $myroot$newname\$newname.suo -force
remove-item $myroot$newname\$newname.sdf -force
#done
来源:https://stackoverflow.com/questions/4232952/what-is-the-fastest-way-script-to-duplicate-visual-studio-project