如何将项目移动到Visual Studio中的不同文件夹?在我的项目中,我习惯了这种结构。
-- app
---- Project.Something
---- Project.SomethingElse
我想将整个命名空间SomethingElse重命名为SomethingNew,最好的方法是什么(无需手动进入.sln文件)?
如何将项目移动到Visual Studio中的不同文件夹?在我的项目中,我习惯了这种结构。
-- app
---- Project.Something
---- Project.SomethingElse
我想将整个命名空间SomethingElse重命名为SomethingNew,最好的方法是什么(无需手动进入.sln文件)?
当前回答
在VS2012中关闭解决方案 将项目移动到新位置 打开你的溶液 选择加载失败的项目 在属性工具窗口中,有一个可编辑的“文件路径”条目,允许您选择新的项目位置 设置新路径 右键单击项目并单击重新加载
其他回答
这在VS2012中很简单;只需使用变更映射特性:
创建要将解决方案移动到的文件夹。 签入所有项目文件(如果您想保留更改),或回滚任何签出的文件。 关闭解决方案。 打开源代码控制资源管理器。 右键单击解决方案,并选择“高级-> Remove Mapping…” 将“Local Folder”的值更改为步骤#1中创建的值。 选择“改变”。 通过在源代码控制资源管理器中双击解决方案来打开解决方案。
通过在“解决方案资源管理器”窗口中右键单击项目并选择“删除”,可以从解决方案中删除项目。移动整个项目文件夹,包括您想要移动的子目录。将项目添加回解决方案。
命名空间名称则完全不同,只需编辑源代码即可。
总结:在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.
我也有同样的问题。我解决了移动参考,在不到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