我当前重命名项目文件夹的解决方案是:
从解决方案中删除项目。在Visual Studio外部重命名文件夹。将项目重新添加到解决方案中。
有更好的方法吗?
我当前重命名项目文件夹的解决方案是:
从解决方案中删除项目。在Visual Studio外部重命名文件夹。将项目重新添加到解决方案中。
有更好的方法吗?
当前回答
首先,关闭localhost,然后右键单击该文件夹。您将获得重命名选项。(Visual Studio 2022)。这对我有用。若你们并没有获得重命名选项,那个么就通过其他解决方案。
其他回答
在文本编辑器中打开.sln,然后在下面的行中将<FolderName>更改为新的文件夹名称项目(“{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}”)=“Ricky”,“\.csproj”,“{021CC6B0-8CFB-4194-A103-C19AF869D965}”
首先,关闭localhost,然后右键单击该文件夹。您将获得重命名选项。(Visual Studio 2022)。这对我有用。若你们并没有获得重命名选项,那个么就通过其他解决方案。
我们最近上传了一个免费Visual Studio扩展的测试版,它为您提供了这些功能。
查看Visual Studio Gallery:Gallery下载
我经常遇到在VisualStudio中重命名项目并编辑文件夹名、项目名和.sln文件以实现这一点的问题。我刚刚写了一个VBScript脚本来完成这一切。您必须小心选择要替换的字符串。
您只需将.vbs文件与解决方案的.sln文件放在同一目录中即可。
' Script parameters'
Solution = "Rename_Visual_Studio_Project" '.sln'
Project = "Rename_Visual_Studio_Project" '.csproj'
NewProject = "SUCCESS"
Const ForReading = 1
Const ForWriting = 2
Set objFso = CreateObject("Scripting.FileSystemObject")
scriptDirr = objFso.GetParentFolderName(wscript.ScriptFullName)
' Rename the all project references in the .sln file'
Set objFile = objFso.OpenTextFile(scriptDirr + "\" + Solution + ".sln", ForReading)
fileText = objFile.ReadAll
newFileText = Replace(fileText, Project, NewProject)
Set objFile = objFSO.OpenTextFile(scriptDirr + "\" + Solution + ".sln", ForWriting)
objFile.WriteLine(newFileText)
objFile.Close
' Rename the .csproj file'
objFso.MoveFile scriptDirr + "\" + Project + "\" + Project + ".csproj", scriptDirr + "\" + Project + "\" + NewProject + ".csproj"
' Rename the folder of the .csproj file'
objFso.MoveFolder scriptDirr + "\" + Project, scriptDirr + "\" + NewProject
其他答案提供了很多关于如何做的细节。不过,这里有一个快捷方式,可以为您节省一些工作:
重命名项目文件夹重命名.csproj文件大规模替换解决方案中所有文件中的项目名称(我使用GrepWin,它有一个方便的GUI和预览)
这样,您就不必在Visual Studio GUI中烦琐地工作了。您也可以通过这种方式修复名称空间。您可以使用源代码控制来验证更改(例如,打开TortoiseGitCommit并查看更改)。