最快的方式/脚本复制Visual Studio项目是什么?

5

你好,我已经创建了一个Visual Studio Express C++项目,并指定了包含头文件和库的路径。 现在,我想复制这个项目,使得路径相同,但是项目名称不同。我不想手动修改.vcproj文件中的名称,有更好的方法吗?

2个回答

10

最简单和最快的方法可能是使用Windows资源管理器来复制整个项目。您很可能需要为复制的.vcproj文件分配一个新的唯一GUID。为此,请在Notepad中打开文件,并从guidgen.exe或类似应用程序中粘贴一个新的ProjectGUID。完成后,您可以简单地在Visual Studio中打开重复的项目并将其重命名。

另一种选择是尝试类似CopyWiz的工具(虽然我从未使用过,但有一个免费试用版本可供您测试是否适用)。

除非您正在尝试创建新项目的模板,在这种情况下有更好的方法


1
对于那些想知道guidgen.exe的位置的人来说,它位于"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin"(我的系统是Windows 7 Professional 64-Bit,安装了VS 2005、2008和2010)。 - kubilay

2
我写了这个代码在PowerShell(Win 7和其他版本均自带)中可以正常运行。即使它对你不起作用,也可能是一个很好的起点。
# 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接