visual-studio 如何重新定位 Visual Studio 项目 (.sln) 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/626631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:15:08  来源:igfitidea点击:

How to Relocate Visual Studio project (.sln) file

visual-studiorelative-path

提问by Brock Woolf

I would like to move the Visual Studio solution (myProject.sln) file into a folder.

我想将 Visual Studio 解决方案 (myProject.sln) 文件移动到一个文件夹中。

The problem with doing this is that all the relative paths in the project will break, how can you relocate the project without updating all relative paths inside the project manually?

这样做的问题是项目中的所有相对路径都会中断,如何在不手动更新项目内部所有相对路径的情况下重新定位项目?

Thanks.

谢谢。

回答by El Cheicon

Just click on the solution in the Solution Explorer and then click on "Save myProject.sln as..." in the File Menu. This will save your .sln in the folder that you choose without breaking the references.

只需单击解决方案资源管理器中的解决方案,然后单击文件菜单中的“将 myProject.sln 保存为...”。这会将您的 .sln 保存在您选择的文件夹中,而不会破坏引用。

回答by savageguy

open the .sln file inside notepad or similiar, near the top it has the relative base path - modify that to suit your needs.

在记事本或类似工具中打开 .sln 文件,在顶部附近有相对基本路径 - 修改它以满足您的需要。

回答by Olivier de Rivoyre

To complete jrummell solution: after editing the *.sln file with the nodepadd, you certainly will have to delete the *.suo files that contains a deprecated cache.

要完成 jrummell 解决方案:在使用 nodepadd 编辑 *.sln 文件后,您当然必须删除包含已弃用缓存的 *.suo 文件。

Note that *.suo files are hidden files in windows 7 (so by default, you do not see it in your explorer).

请注意,*.suo 文件是 Windows 7 中的隐藏文件(因此默认情况下,您在资源管理器中看不到它)。

回答by Law

With source control this is a little tricky. I just needed to move my solution .sln file up one level for easy access while maintaining source control history. I followed the advice of the previous posts but ran into a situation where TFS wanted to move all my projects with the solution. I accomplished this task using a combination with the following steps:

对于源代码控制,这有点棘手。我只需要将我的解决方案 .sln 文件上移一层,以便在保持源代码控制历史记录的同时轻松访问。我遵循了之前帖子的建议,但遇到了 TFS 想要使用解决方案移动我所有项目的情况。我结合以下步骤完成了这项任务:

  1. Make sure solution is not open.
  2. Un-map solution from local drive.
  3. Right click Solution (.sln) in Source Control Explorer and select Move as mentioned above. Set the path of the new folder and select OK.
  4. Checkin that change.
  5. Checkout solution .slnand then edit the solution in notepad. You will see that the projects are assigned guids and there are file paths to the projects. You need to change all of those paths relative to where your new solution file .slnresides. Be sure and use double slashes for unique names and paths:
  1. 确保解决方案未打开。
  2. 从本地驱动器取消映射解决方案。
  3. 在源代码管理资源管理器中右键单击解决方案 (.sln) 并选择如上所述的移动。设置新文件夹的路径并选择确定。
  4. 检查该更改。
  5. 签出解决方案.sln,然后在记事本中编辑解决方案。您将看到为项目分配了 guid,并且有项目的文件路径。您需要更改所有这些相对于新解决方案文件.sln所在位置的路径。确保对唯一名称和路径使用双斜杠:

GlobalSection(TeamFoundationVersionControl) = preSolution

GlobalSection(TeamFoundationVersionControl) = preSolution

SccProjectUniqueName1 = MyNewFolder\\MyProject.Common\\MyProject.Common.csproj

SccProjectUniqueName1 = MyNewFolder\\MyProject.Common\\MyProject.Common.csproj

SccProjectTopLevelParentUniqueName1 = MySolution.sln

SccProjectTopLevelParentUniqueName1 = MySolution.sln

SccProjectName1 = MyNewfolder/MyProject.Common 
SccLocalPath1 = MyNewFolder\MyProject.Common

Check-in and re-map solution to local drive. This worked for me. Hope it helps!

签入并将解决方案重新映射到本地驱动器。这对我有用。希望能帮助到你!

回答by jrummell

You can update the relative paths to each project in a text editor.

您可以在文本编辑器中更新每个项目的相对路径。