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

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

有官方的做法吗?


当前回答

如果您正在Visual Studio 2010中创建网站。您可以按照如下方式修改项目名称。

步骤1:在Visual Studio 2010中,SLN文件将存储在Visual Studio 2010的项目文件夹下,源文件存储在Visual Studio 2010的网站文件夹下。

步骤2:重命名文件夹右键单击该文件夹通过重命名,其中包含您的SLN项目。

步骤3:重命名SLN文件名右键单击该SLN文件转发重命名。

第四步:在Visual Studio 2010的Website下重命名包含SLN文件Source的文件夹。

步骤5:然后最后双击您的SLN文件,并更改您的SLN源文件夹的根。

其他回答

删除bin和obj子文件夹以删除不正确的引用,然后使用windows搜索旧名称。

编辑任何代码或xml文件发现和重建,现在应该是好的。

连同这个链接的答案

https://stackoverflow.com/a/19844531/6767365

重命名这些文件。 我把我的项目重命名为MvcMovie,它工作得很好

唯一的解决方案,为我在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。配置和重新启动迁移(如果项目中有迁移的话)。

下面是在Visual Studio 2013中逐步重命名整个解决方案的方法

假设我们正在更改一个名为“HelloWorld”的项目。到Section1to5.ui

转到解决方案资源管理器(截图如下),右键单击您希望重命名的项目,并选择“重命名”。输入所需的新名称。

Right click on the Project that you have just renamed, and click on "Properties". Under the Application tab, change the "Assembly name" and "Default namespace". In the main Program.cs file (or any other code files that you may have created), 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 HelloWorld.ui ----> namespace Section1to5.ui Next, expand the "Properties" and double click on AssemblyInfo.cs file. You will notice the below code fragment:

[组装:AssemblyTitle(“HelloWorld.ui”)] [组装:AssemblyDescription (" ")) [组装:AssemblyConfiguration (" ")) [组装:AssemblyCompany(“微软”)] [组装:AssemblyProduct(“HelloWorld.ui”)] [assembly: AssemblyCopyright("Copyright©Microsoft 2015")] [组装:AssemblyTrademark (" ")) [组装:AssemblyCulture (" "))

您需要将Properties/AssemblyInfo.cs中的AssemblyTitle和AssemblyProduct更改为新名称,在本例中为“HelloWorld”。“Section1to5.ui”。更改完名称后,保存并关闭Visual Studio。

在项目目录中,进入“HelloWorld”文件夹。删除bin和obj目录。 完成后,将文件夹重命名为“HelloWorld”。到新的项目名称。 用文本编辑器(如Notepad或notepad++)打开重命名的解决方案文件,并编辑以下行: Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld. "ui”、“HelloWorld.ui \ HelloWorld.ui。csproj”、“{39 fc65a3 - 3 - ae7 4 - ec9 b8f7 - 74 f971636c70}”

替换“HelloWorld”的所有实例。你为你的项目选择的新名称,在本例中是“Section1to5.ui”。这将把项目的路径更改为步骤6中重命名的目录。

使用visual studio打开解决方案文件,并清理和重建项目。 您可能注意到“调试/运行”按钮已被“附加”按钮所取代。如果发生这种情况,只需右键单击项目并选择“设置为启动项目”选项。或者单击“工具>自定义>命令>添加命令>调试”,添加按钮。

你完成了重命名项目,如果你有任何疑问,请随时发帖,我很乐意帮助你!

如果在加载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后生成该名称。