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

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

有官方的做法吗?


当前回答

2021年更新:

重命名项目使这变得毫不费力。一个简单的CLI工具,它甚至在成功时创建一个git提交。

https://github.com/ModernRonin/ProjectRenamer


旧的回答:

我曾经使用Visual Studio扩展“完全重命名项目”来成功地重命名ASP中的项目。NET Core 2解决方案。

我使用ReSharper然后调整名称空间(右键单击项目,重构,调整名称空间…)

https://github.com/kuanysh-nabiyev/RenameProjectVsExtension

其他回答

删除/添加项目文件方法

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

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

优势

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

缺点

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

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

如果在加载Xamarin等共享项目时遇到问题,请记住在csproj文件中更改对共享库的引用。我开发了一款CocosSharp游戏,但Droid/iOS/WP81项目不想加载。我不得不在每个csproj文件(Driod/iOS/WP81)中更改下面的行,其中引用了共享库。这是由于文件夹名称更改造成的,因此将YOUR_PREVIOUS_NAMESPACE替换为文件夹的新名称。

<Import Project="..\YOUR_PREVIOUS_NAMESPACE.Shared\EmptyProject.Shared.projitems" Label="Shared" />

另外,我注意到对于. driod项目,项目属性中的程序集名称不能使用Visual Studio更改(我使用2015年)。我必须在. droid中手动更改程序集名称。csproj文件。

<AssemblyName>YourNameSpace</AssemblyName>

然后我加载解决方案,在项目属性视图新名称出现。重建dll后生成该名称。

重命名一个解决方案:

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". In the main cs file (or any other code files), 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: namespace WindowsFormsApplication1 Change the AssemblyTitle and AssemblyProduct in Properties/AssemblyInfo.cs. [assembly: AssemblyTitle("New Name Here")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("New Name Here")] [assembly: AssemblyCopyright("Copyright © 2013")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] 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. Clean and Rebuild the project.

我是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.

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

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

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

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