如何将项目移动到Visual Studio中的不同文件夹?在我的项目中,我习惯了这种结构。

-- app
---- Project.Something
---- Project.SomethingElse

我想将整个命名空间SomethingElse重命名为SomethingNew,最好的方法是什么(无需手动进入.sln文件)?


通过在“解决方案资源管理器”窗口中右键单击项目并选择“删除”,可以从解决方案中删除项目。移动整个项目文件夹,包括您想要移动的子目录。将项目添加回解决方案。

命名空间名称则完全不同,只需编辑源代码即可。


我尝试了删除和重新添加项目的建议,但修复依赖关系可能会很痛苦。

我使用这种方法:

移动项目文件夹。 如果项目在源代码控制中,则使用源代码控制命令执行移动。 在文本编辑器中编辑解决方案文件。你应该只需要改变一条路径。


在VS2012中关闭解决方案 将项目移动到新位置 打开你的溶液 选择加载失败的项目 在属性工具窗口中,有一个可编辑的“文件路径”条目,允许您选择新的项目位置 设置新路径 右键单击项目并单击重新加载


这在VS2012中很简单;只需使用变更映射特性:

创建要将解决方案移动到的文件夹。 签入所有项目文件(如果您想保留更改),或回滚任何签出的文件。 关闭解决方案。 打开源代码控制资源管理器。 右键单击解决方案,并选择“高级-> Remove Mapping…” 将“Local Folder”的值更改为步骤#1中创建的值。 选择“改变”。 通过在源代码控制资源管理器中双击解决方案来打开解决方案。


使用解决方案文件夹将相关项目分组在一起

见http://msdn.microsoft.com/en-us/library/vstudio/c6c756s6 (v = vs.100) . aspx


在VS 2015

在解决方案资源管理器中卸载项目 创建一个新的解决方案 将项目复制到新解决方案的文件夹中 右键单击解决方案,添加现有项目。 如果使用MVC等框架,则可能需要在引用管理器中添加引用。


对我有效的方法是:

从解决方案中删除项目。 使用文本编辑器编辑项目文件。 更新“包”的所有相对路径。就我而言,我不得不改变。\包裹到..\..\包,因为我把项目移动到一个更深的文件夹。 将项目加载回解决方案中。


我也有同样的问题。我解决了移动参考,在不到15分钟,没有改变参考。

对我来说,解决办法很简单:

Move your files where you need. Delete the folder with name .vs. Must be as not visible folder. Open the solution file (.sln) using a simple editor like note or notepad++. Change the reference where your file is, using the following structure: if you put your project in the same folder remove the previous folder or the reference "..\"; if you put in a above folder add the reference "..\" or the name of the folder. Save the file with the changes. Open the project file (.csproj) and do the same, remove or add the reference. Save the changes. Open the solution file.

例子:

在解决方案文件(.sln)中

Original: Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PATH1.UI", "ScannerPDF\PATH1.UI\PATH1.UI.csproj", "{A26438AD-E428-4AE4-8AB8-A5D6933E2D7B}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PATH1.DataService", "ScannerPDF\PATH1.DataService\PATH1.DataService.csproj", "{ED5A561B-3674-4613-ADE5-B13661146E2E}" New: Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PATH1.MX.UI", "PATH1.MX.UI\PATH1.UI.csproj", "{A26438AD-E428-4AE4-8AB8-A5D6933E2D7B}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PATH1.DataService", "PATH1.DataService\PATH1.DataService.csproj", "{ED5A561B-3674-4613-ADE5-B13661146E2E}"

在项目文件中:

原: 新: 原始参考: …\ lib \ RCWF \ 2018.1.220.40 \ TelerikCommon.dll 新的参考: . . \ lib \ RCWF \ 2018.1.220.40 \ TelerikCommon.dll


我发现这个方法,这个方法对我有用。

在visual studio 2017社区版中,它在此路径创建一个项目 ”马克C: \用户\ \ \回购\产生来源\产生” 这将产生一个文件访问被拒绝的问题

现在,你可以用这种方法解决这个问题。

close your visual studio process. Then, find your project and copy the project folder But, first make a Sub-folder Named Projects inside of your visual studio 2017 folder in documents. Next, paste the project folder inside of your visual studio 2017 Project folder not the main visual studio 2017 folder it should go into the Sub-folder called Projects. Next, restart Visual studio 2017 Then, choose Open project Solution Then, find your project you pasted in your visual studio 2017 Projects folder Then clean the Project and rebuild it , It, should build and compile just fine. Hope, this Helped out anybody else. Not to sure why Microsoft thought building your projects in a path where it needs write permissions is beyond me.


我希望Git中的更改显示为移动/重命名,而不是删除和添加。 所以我把上面的文章和这篇文章结合起来。

mkdir subdirectory
git mv -k ./* ./subdirectory
# check to make sure everything moved (see below)
git commit

并通过文本编辑器从sln文件中的nuget Pkg中调整项目和组件的路径。


在visual studio community 2019中,我做了Victor David Francisco Enrique说的,但只需要删除.vs invisible文件夹


复制项目文件夹到新目标 从解决方案中删除项目(在“解决方案资源管理器”中右键单击项目并选择“删除”) 然后将现有项目添加到解决方案中(在“解决方案资源管理器”中右键单击项目,选择“添加”,然后选择“现有项目”) 将路径更改为“YourProjectName”中的“packages”文件夹。csproj"文件(在记事本中打开并更改链接包的路径)


总结:在VS2019中使用git重命名和移动,保留git历史,利用一点r#,自动依赖项目引用更新(对于许多项目的sln来说很重要,我们有>200)

我一直在使用以下步骤在Visual Studio 2019中重命名和移动c#项目。这个过程使用r#来调整名称空间。git历史记录通过“git mv”(避免添加/删除历史记录)来保留。

两个阶段:1)重新命名项目,2)移动项目。

(使用技巧从base2卸载项目。)

重命名

VS | Solution Explorer | right-click project | Rename (e.g., Utils.Foo to Foo). VS | Solution Explorer | right-click project | Properties | change assembly name, default namespace and Assembly Information fields Do 1 and 2 for corresponding test project (e.g., Utils.Foo.Tests) VS | Solution Explorer | right-click projects (production and test) | Refactor | Adjust Namespaces XAML files that use the project may need to be updated (manually or with an appropriate global search and replace) Rebuild All Commit!! (to commit changes before moves)

注意:Windows资源管理器中的文件夹到目前为止仍然是旧名称(例如Utils.Foo)。这在移动步骤中是固定的。

Move

这种方法:1)保留git历史,2)利用r#原子地调整名称空间,3)大量更新依赖的项目(避免手动编辑依赖的sln和csproj文件)。

卸载解决方案中的所有项目(这样目标项目的删除就不会触发相关项目的更改) VS |选择解决方案|下的所有解决方案文件夹,右键单击卸载项目 使用git移动文件夹(保存历史记录)

a)打开2019年的开发者命令提示符

B) git状态(以说明“没有提交,工作树干净”)

C)完成项目 例如,git mv“C:\Code\foo\foo\Utils。代码Foo " C: \ \ Foo”

D) git状态查看/验证更改

删除项目

VS |解决方案资源管理器|选择项目|右键单击|删除 (因为所有的项目都是卸载的,这将正确地不删除对它的依赖项目的引用)

重新添加项目(到解决方案资源管理器树中的新位置)

a) VS |解决方案资源管理器|选择目标父文件夹|右键单击|添加|现有项目

重新加载所有项目

重要:确认*。已更新依赖项目的Csproj文件。

(VS | Team Explorer | Changes |双击任何依赖csproj列出的| inspect-verify ProjectReference路径更改)

手动固定路径在单个移动*。csproj文件

使用notepad++(或其他文本编辑器)来修复路径。这通常可以通过简单的搜索和替换来完成(例如,../../../..)/ to ../../)。

这将更新…

a) GlobalAssmeblyInfo.cs引用

B)包的路径

c)依赖关系验证图文件的路径

d)到规则集路径的路径(例如,<CodeAnalysisRuleSet>.. .. .. .. ..\SolutionDependencyValidation\IgnoreWarnings.ruleset</CodeAnalysisRuleSet>)

关闭并重新打开解决方案(以使项目引用处于良好状态)

保存全部,关闭解决方案,我更喜欢删除bin和obj文件夹以清除历史,重新打开解决方案

验证

a) VS |团队资源管理器|更改

i)应该看到显示移动文件的阶段性更改 Ii)应该看到被很好地更新的依赖项目(*.csproj) 回顾一下csproj的差异,注意路径已经被漂亮地更新了!!(这是避免使用文本编辑器手动更新csproj文件的神奇之处)

b)在Windows资源管理器中,验证旧位置为空

c)清洁解决方案,重建解决方案,运行单元测试,启动应用程序在sln。

提交! !


This worked for me vb2019. I copied my source project folder. I then pasted the project, and renamed the the folder to whatever. In order to break the ties back to the source project folder, I temporarily renamed the source folder. I opened my destination project. The paths to the forms and modules were re-discovered in the local folder. I went through all my forms and modules to make sure they were working. I ran the project. I closed the project. I renamed the source project folder back to is't original name. I can open both projects at the same time without errors.


不知道为什么所有的答案都忽略了最简单的解决方案。只需运行“命令提示应用程序”(在窗口栏中搜索CMD,它将自动出现)

然后只需输入以下命令(根据您自己的情况更改路径:)

robocopy /E C:\Users\Peter\source\repos D:\Peter\repos

robocopy所做的是“将文件数据从一个位置复制到另一个位置”,“秘密源”是/ E,意思是“复制子目录”。此选项自动包含空目录。”

享受! !: -)


关闭解决方案并将项目移动到新的文件夹/位置 重新打开溶液 项目应该加载的'+'叹息指的是未检查的部分。所有的文件 将显示为“重命名”。 如果重新打开后不工作,右键单击项目,然后单击卸载 重新加载。 它在VS2019中有效


最简单的方法,我自己找到的

我试了很多次,直到找到一个可行的方法。例如,您想要将项目从sln文件夹移动到mySource文件夹。

Remove your Project: In the SolutionExplorer of Visual Studio select your Project you want to change the directory, Press Delete -> Project gets removed. It still remains in your sln folder. Copy it to your Path: In the windows explorer copy your whole project to your mySource folder. -> Now you are ready to include it. Include back your Project: In the SolutionExplorer of Visual Studio add Existing Project and select your project from mySource folder. -> Project is now back in your Solution. Adjust your Project References: Check every Reference in your Project. On your Project -> Dependencies -> Project -> you see your project references. If there is a yellow Warning sign on a project reference than is it wrong. Delete your project reference and add it new. Rebuild your Project: and let it Run. Afterwards you can delete your project in the sln folder, which is not anymore in use.

这工作。玩得开心!