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

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

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


当前回答

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

在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.

其他回答

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

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

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

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

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

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

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

享受! !: -)

总结:在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.