简体   繁体   English

将Visual Studio解决方案添加到Visual Studio中的现有解决方案

[英]Add Visual Studio solution to existing solution in Visual Studio

I wrote an application in Visual Studio C# 2010, that I would like to import into another existing Visual Studio C# 2010 Application. 我在Visual Studio C#2010中编写了一个应用程序,我想将其导入另一个现有的Visual Studio C#2010应用程序中。 How would I go about doing this? 我将如何去做呢?

For instance, I'd like to import the project into another, and basically copy/paste the interface from the application into a tabpage on a tab control I have. 例如,我想将项目导入另一个项目,并且基本上将接口从应用程序复制/粘贴到我拥有的选项卡控件的选项卡页中。

Any assistance or advice on how to do this is greatly appreciated! 非常感谢您提供任何有关此操作的帮助或建议!

You should be able to copy the physical files using windows from the existing solution location to the new solution location. 您应该能够使用Windows将物理文件从现有解决方案位置复制到新解决方案位置。

Then once the copy is complete open Visual studio and tell it you want to add an existing project. 复制完成后,打开Visual Studio,并告诉您要添加现有项目。 Navigate to the folder where the files are on the filesystem and open the project file. 导航到文件在文件系统上的文件夹,然后打开项目文件。

Once you save the solution it should from that point forward have the new projects in the new solution. 保存解决方案后,从那时起应该在新解决方案中包含新项目。

There are several ways to achieve this - Copy & Paste being one of them (but the least beautiful of course). 有几种方法可以实现此目的-复制粘贴就是其中一种(当然,最差的一种)。 A more promising one is the following: 更有希望的是:

  • Wrap the user interface you want to share in a User Control in the existing project. 在现有项目的用户控件中包装要共享的用户界面。 Also include the code behind logic in this user control. 在此用户控件中还应包含逻辑代码。 Include the user control in the project and make sure that everything works before continuing. 将用户控件包括在项目中,并确保一切正常,然后再继续。
  • Add the existing project to the new solution. 将现有项目添加到新解决方案中。 It is advised that you create a hierarchical structure in the file system for the solution so that all projects in the solution are located under a directory. 建议您在文件系统中为解决方案创建分层结构,以便解决方案中的所有项目都位于目录下。
  • Reference the project from the project that wants to access the user interface. 从要访问用户界面的项目中引用该项目。 As the projects are in the same solution, you can add a project reference. 由于项目在同一个解决方案中,因此您可以添加项目参考。 This asserts that the projects are built together. 这断言项目是一起构建的。
  • Place the user control on the tab page. 将用户控件放在选项卡页上。

As an alternative, you can also pass on adding the project to the solution but only create a user control and add a binary reference from the other project. 作为替代方案,您还可以继续将项目添加到解决方案中,但仅创建用户控件并从其他项目添加二进制引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM