我有一个相当复杂的Visual Studio解决方案(2010年,但这不重要),我需要重命名。

我想重命名文件夹以匹配新的解决方案名称,但我无法找到自动重构文件夹名称的方法,而且查看每个项目文件将是一件痛苦的事情。

有官方的做法吗?


当前回答

重命名网站:

http://www.c-sharpcorner.com/Blogs/46334/rename-website-project-in-visual-studio-2013.aspx

定位并编辑IISExpress的applicationhost。配置,在这里找到: C: \用户{username} \ \ IISExpress \ config文件

其他回答

手动编辑。sln文件

这个方法完全是为了重命名项目的目录,就像在Windows资源管理器中看到的那样。

这种方法不会遇到下面的删除/添加项目文件方法中的问题(引用消失),但如果项目处于源代码控制之下,它可能会导致问题(参见下面的注释)。这就是为什么第二步(备份)如此重要。

Close Visual Studio. Create a backup of your .sln file (you can always roll back). Imagine you want to rename directory Project1 to Project2. If not using source control, rename the folder from Project1 to Project2 using Windows Explorer. If using source control, rename the folder from Project1 to Project2 using the functions supplied by source control. This preserves the history of the file. For example, with TortoiseSVN, right click on the file, select TortoiseSVN .. Rename. In the .sln file, edit all instances of Project1 to be Project2, using a text editor like NotePad. Restart Visual Studio, and everything will work as before, but with the project in a different directory.

你也可以看到重命名解决方案手动或帖子,其中描述了这个手动过程。

优势

您可以使Windows资源管理器中的目录与解决方案中的项目名称相匹配。 该方法不会从其他项目中删除对该文件的任何引用(与删除/添加项目文件方法相比,这是一个优点,请参阅下面我的其他回答)。

警告

It's important to back everything up into a .zip file before renaming anything, as this method can create issues with source control. If your project is under source control, it may create issues if you rename files or directories outside of source control (using Windows Explorer). Its preferable to rename the file using the source control framework itself, if you can, to preserve the history of that file (check out the context menu on a right click - it may have a function to rename the file).

更新2014-11-02

ReSharper添加了一个自动化的方法来实现与上面的手动方法相同的结果。如果命名空间下划线是弯曲的蓝色线,单击动作金字塔图标:

重命名命名空间以匹配Windows资源管理器中的目录名称,或者; 重命名Windows资源管理器中的目录以匹配命名空间。

在第二种情况下,最后一个词定义了Windows资源管理器中的新目录名称,例如,如果我们将命名空间更改为ViewModel2,它将提供将文件移动到文件夹ViewModel2。

但是,这并不一定会更新源代码控制中的文件,因此您可能仍然必须使用手动方法。

更新2018-01-31

用Visual Studio 2008、2010、2012、2013、2015、2017更新1、2、3、4、5测试。

更新2020-05-02

使用Visual Studio 2019进行测试。

更新2021-11-19

重新测试。仍能工作。

更新2022-11-30

最新版本的Git应该自动检测文件重命名,因此不需要额外注意保存差异的历史。

如果在遵循建议的解决方案之后,您已经设法重命名了一个新的解决方案(假设从www.oldsite.com重命名为www.newsite.com),但仍然使用旧的Web站点项目名称,因为您有一个旧的“ASP。Net Web站点”,然后遵循这些额外的步骤(假设从project1到project2)。

安装和旧的Visual Studio 2017 用它打开项目,右键单击项目->添加->新建项目。 选择“已安装-> Visual c# -> Web ->以前版本-> ASP. exe”。NET空网站”并将其命名为“www.newsite.com” 将Visual Studio 2017中的所有文件和文件夹从旧站点移动到新站点,直到旧站点仍然为空。 右键单击“www.oldsite.com”并删除它。

现在您可以保存所有内容,并使用Visual Studio 2022再次打开它。所有这些都是需要的,因为VS2019/VS2020不支持“旧的”ASP。Net网站创建,但只编辑。

我尝试了Visual Studio Project Renamer,但是,它在我尝试的少数情况下抛出异常。

我在CopyWiz上取得了很大的成功。

我与他们没有任何关系,我还没有为它付钱,但我可能很快就要为它付钱了,因为它似乎是唯一一个对我的c#和c++项目都有效的工具。我确实希望他们能赚点钱,并继续改进它。

使用notepad++的“在文件中查找”功能对我来说很好(ctrl + H,在文件中查找)。

http://notepad-plus-plus.org/download/v6.2.2.html

如果要重命名解决方案,可以执行以下步骤。

Backup.First things first, make sure to always create a backup file.Simply copy your project to a different directory. In Solution Explorer, right-click the project, select Rename, and enter a new name. In Solution Explorer, right-click the project and select Properties. On the Application tab, change the "Assembly name" and "Default namespace". Open any .cs and rename all namespace Change the AssemblyTitle and AssemblyProduct in Properties/AssemblyInfo.cs. Delete bin and obj directories physically. Rename the project physical folder directory. Open the Sln file (within notepad or any editor) and change the path to the project. Cleans and Rebuild the project

https://learn.microsoft.com/en-us/answers/questions/1028483/rename-solution-and-related-projects-in-a-aspnet-w.html细节……