visual-studio 将解决方案文件更改为其他文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3377917/
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 12:17:59  来源:igfitidea点击:

change solution file to a different folder

visual-studiovisual-studio-2008

提问by Josh

How do I change the folder of my existing solution file (sln)?

如何更改现有解决方案文件 (sln) 的文件夹?

It's right now inside one of my project's folder; if I cut the solution file and paste it in the root folder,it doesn't load any of my projects.

它现在在我的项目文件夹之一中;如果我剪切解决方案文件并将其粘贴到根文件夹中,它不会加载我的任何项目。

采纳答案by RWGodfrey

The solution file is just a text file. You should be able to move it and then edit it to make sure that any relative paths referenced in the file are correct.

解决方案文件只是一个文本文件。您应该能够移动它然后编辑它以确保文件中引用的任何相对路径都是正确的。

I've also been able to right-click on the solution file in the solution explorer and then use save-as to save it in a different location. That doesn't seem to work everytime for me though.

我还能够在解决方案资源管理器中右键单击解决方案文件,然后使用另存为将其保存在不同的位置。不过,这对我来说似乎并非每次都有效。

回答by Martin

Open solution explorer in Visual Studio and select the solution.
Click on File > Save MyProject.sln As ...
and choose the new location.

在 Visual Studio 中打开解决方案资源管理器并选择解决方案。
单击文件 > 将 MyProject.sln 另存为 ...
并选择新位置。

回答by googleforhelp

Open a blank solution, save it to a location where you would like to move. Then add "Existing Project" and select the Old.sln file to add all the projects under the old solution file.

打开一个空白解决方案,将其保存到您想要移动的位置。然后添加“Existing Project”,选择Old.sln文件,添加旧解决方案文件下的所有项目。

回答by Philip.ie

I just had to do this with some legacy projects I inherited so thought it might be worth documenting...

我只需要用我继承的一些遗留项目来做这件事,所以我认为这可能值得记录......

After upgrading from VS 2005 solution, I noticed that the solution file was at the same level as the project files. Our standard is to have the solution file one level above.

从 VS 2005 解决方案升级后,我注意到解决方案文件与项目文件处于同一级别。我们的标准是将解决方案文件上一级。

Undesired location of solution file.

解决方案文件的不需要的位置。

Opening the solution file in 'Notepad' I see the following:

在“记事本”中打开解决方案文件,我看到以下内容:

Unchanged Solution file opened in notpad.

在记事本中打开的未更改解决方案文件。

Add required relative path to each of the project path and save in correct location:

将所需的相对路径添加到每个项目路径并保存在正确的位置:

In my case to bring up one level 'BloombergPriceRequestService\'

在我的情况下,提出一个级别“BloombergPriceRequestService\”

SOproject line(s) will look like this:

SO项目行将如下所示:

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BloombergPaydownService", "BloombergPaydownService\BloombergPaydownService.csproj", "{17DDDD3E-CD39-48B4-BE3F-71E550FCBBFC}"
EndProject
Global

Don't forgetto delete your old solution file! I have moved the solution file up one level

不要忘记删除旧的解决方案文件! 我已将解决方案文件上移一级

回答by Krevan

if I cut the sln file and paste it in the root folder,it doesn't load any of my projects

如果我剪切 sln 文件并将其粘贴到根文件夹中,它不会加载我的任何项目

Do this anyway, and try to open the solution. It will tell you that some projects couldn't be loaded: ignore the warning.

无论如何都要这样做,并尝试打开解决方案。它会告诉您无法加载某些项目:忽略警告。

Then, go ahead and delete all the projects from the solution. After this right click the solution and select Add => Existing projectand browse to your project file. Repeat for all projects in your solution.

然后,继续并从解决方案中删除所有项目。在此之后右键单击解决方案并选择Add => Existing project并浏览到您的项目文件。对解决方案中的所有项目重复此操作。

回答by balamurugan

Sometimes, the solution file may contain more than 5 projectsattached to it.

有时,解决方案文件可能包含5 个以上的项目

In that case, Creating the new solution and adding projects to that is cumbersome and takes more time.

在这种情况下,创建新解决方案并向其中添加项目很麻烦并且需要更多时间。

You can just edit the solution file to load the projects correctly.

您只需编辑解决方案文件即可正确加载项目。

Steps to do

要做的步骤

sdas 1. Open the solution file in notepad or any text editor. 2. update the path which is underlined and made bold.

sdas 1. 在记事本或任何文本编辑器中打开解决方案文件。2.更新下划线加粗的路径。

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BloombergPaydownService", "BloombergPaydownService\BloombergPaydownService.csproj", "{17DDDD3E-CD39-48B4-BE3F-71E550FCBBFC}"

项目("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BloombergPaydownService", " BloombergPaydownService\BloombergPaydownService.csproj", "{17DDDD3E-CD39-48B4-BE3F-71E550FC}"

  1. Save the file and open in Visual studio.
  1. 保存文件并在 Visual Studio 中打开。

回答by Hari

There are two ways you can do it:

有两种方法可以做到:

  1. Simply delete the entire project and create the entire project again in the other folder ( which is not recommended).
  2. Here are the steps to follow without missing any files.

    a. Goto Source control explorer Create a new folder or Just move the solution to which you want to move the folder to.

    b. Load the solution in your local and it will prompt a message saying that do you want to reload it from source control? click yes.

    c. Once we load the solution you will see that the project you have moved won't be loaded (Since we moved to the other folder)

    d. So now, Remove the project which was not loaded and then add it as an existing project

    e. I am sure that if you have added nugetPackages they won't get loaded.

    f. Goto file explorer of the particular project? open the .csproj file and try to check the packages location, Error condition, Project reference and Import and apart from them if there are any Which are pointing to a directory.

    g. The simplest way is just adding some nuget package and see what is the path generated by visual studio.

    h. Once we change the locations they will be loaded in references

    i. After adding references try to build the solution and it will throw some build errors because we moved the project from one folder to other.

    j. Add the project reference wherever needed after moving the files

    k. Now the build will be succeeded.

  1. 只需删除整个项目并在另一个文件夹中再次创建整个项目(不推荐)。
  2. 以下是在不丢失任何文件的情况下遵循的步骤。

    一个。转到源代码管理资源管理器创建一个新文件夹或仅移动要将文件夹移动到的解决方案。

    湾 在您的本地加载解决方案,它会提示一条消息,说您要从源代码管理重新加载它吗?单击是。

    C。一旦我们加载了解决方案,您将看到您移动的项目不会被加载(因为我们移动到另一个文件夹)

    d. 所以现在,删除未加载的项目,然后将其添加为现有项目

    e. 我敢肯定,如果您添加了 nugetPackages,它们将不会被加载。

    F。转到特定项目的文件浏览器?打开 .csproj 文件并尝试检查包位置、错误条件、项目引用和导入,如果有任何指向目录,则除此之外。

    G。最简单的方法就是添加一些nuget包,看看visual studio生成的路径是什么。

    H。一旦我们更改位置,它们将被加载到引用中

    一世。添加引用后尝试构建解决方案,它会抛出一些构建错误,因为我们将项目从一个文件夹移动到另一个文件夹。

    j. 移动文件后在需要的地方添加项目引用

    克。现在构建将成功。

回答by user1000008

Editing the solution file is a hazardous way to do things and I found a better way. Just create a new solution and add copies of the folders containing the various projects (in their respective folders) to the project.

编辑解决方案文件是一种危险的做事方式,我找到了更好的方法。只需创建一个新的解决方案并将包含各种项目的文件夹副本(在它们各自的文件夹中)添加到项目中。