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

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

有官方的做法吗?


当前回答

重命名网站:

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

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

其他回答

如果在遵循建议的解决方案之后,您已经设法重命名了一个新的解决方案(假设从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网站创建,但只编辑。

The Rename operations in Visual Studio only change the filename, i.e. *.prj for a project, and *.sln for a solution. You will need to rename folders separately using the filesystem, and you will need to remove and re-add the projects since they will have new folder names. However, note that the solution and project files are respectively text and xml files. You could write your own program that parses them and renames both the folder names, filenames, and fixes the project/solution files internally.

唯一的解决方案,为我在Visual Studio 2013在一个WEB项目:

假设我想将“project1”重命名为“project2”。 假设我的.sln文件的物理路径是: c: \ \ \ project1 \ project1.sln路径

因此,我的.csproj文件以及bin和obj文件夹的路径应该是: c: \我\ \ project1 \ project1 \路径

Open the solution in VS by double clicking the project1.sln file. In Solution Explorer, right-click the project (NOT the solution!!!), 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". In the main CS file (or any other code files like Global.asax for example), rename the namespace declaration to use the new name. For this right-click the namespace and select Refactor > Rename enter a new name. For example:

名称空间project1

4.1在“解决方案资源管理器”中,右键单击项目(不是解决方案!!),选择“重命名”,并输入新的名称。

请确保:Properties/AssemblyInfo.cs中的AssemblyTitle和AssemblyProduct被设置为新名称(“project2”)。

1 [assembly: AssemblyTitle(“这里的新名称”)] 2 [组装:AssemblyDescription (" ")) 3. [组装:AssemblyConfiguration (" ")) 4 [组装:AssemblyCompany (" ")) 5 [assembly: AssemblyProduct(“这里的新名称”)] 6 [assembly: AssemblyCopyright(“版权©2013”)] 7 [组装:AssemblyTrademark (" ")) 8 [组装:AssemblyCulture (" "))

关闭Visual Studio。 从物理上删除bin和obj目录。 重命名父文件夹和源文件夹为新名称(project2):

在这个例子中: 我c: \ \路径\ project1 \ project1

将会是: c: \ \ \ project2 \ project2路径

重命名SLN文件名右键单击该SLN文件转发重命名。 最后打开SLN文件(在记事本或任何编辑器内),复制并替换(Ctrl+h)任何旧名称到新名称。 打开VS,点击BUILD -> Clean Solution 点击构建->构建解决方案,然后F5运行… 注1:如果你得到这样的东西:编译错误 CS0246:无法找到类型或名称空间名称“project2”(您是否缺少using指令或程序集引用?)

c:\Users\Username\AppData\Local\Temp\Temporary ASP. exe网络文件\ \ 78 dd917f \ d0836ce4 \ App_Web_index.cshtml.a8d08dba.b0mwjmih.0.cs根源

然后进入“临时ASP。NET Files”文件夹并删除所有文件。

注2:如果你试图“另存为”到一个新命名的项目,并保留旧的项目,考虑通过修改web中的connectionStrings来复制你的db。配置和重新启动迁移(如果项目中有迁移的话)。

我是vs的新手,我只是遇到了同样的问题:需要在工作几周后重新命名一个已经开始的项目。我就是这么做的,而且成功了。

Just in case, make a backup of your folder Project, although you won't be touching it, but just in case! Create a new project and save it using the name you wish for your 'new' project, meaning the name you want to change your 'old' project to. Build it. After that you'll have a Project with the name you wanted but that it does not anything at all but open a window (a Windows Form App in my case). With the new proyect opened, click on Project->Add Existing Ítem and using Windows Explorer locate your 'old' folder Project and select all the files under ...Visual Studio xxx\Projects\oldApp\oldApp Select all files in there (.vb, .resx) and add them to your 'new' Project (the one that should be already opened). Almost last step would be to open your Project file using the Solution Explorer and in the 1st tab change the default startup form to the form it should be. Rebuild everything.

可能会有更多的步骤,但更少或根本不需要输入,只需要点击鼠标。希望 这很有帮助:)

删除/添加项目文件方法

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

使用GIT、SVN或WinZip(很重要!)等工具备份整个项目。 在Visual Studio中的解决方案中,删除项目。 在Windows资源管理器中重命名目录。 在Visual Studio中再次添加项目。

优势

您可以使Windows资源管理器中的目录与解决方案中的项目名称相匹配。

缺点

如果删除一个库,它将从其他项目中删除对该库的任何引用。在此之后,解决方案可能无法编译,直到您将该库的引用添加回(这非常简单)。这就是第一步(备份)如此重要的原因。 如果您有源代码控制,则会丢失文件的历史记录。

右键单击一个项目并选择“在Windows资源管理器中打开文件夹”对于跟踪项目在执行此过程中的存储位置非常有用。