简体   繁体   English

当无法构建通用程序集时,在Visual Studio 2008的解决方案中的项目之间共享代码

[英]Share code between projects in a solution in Visual Studio 2008, when building a common assembly is impossible

I create an add-on for the product Foo. 我为产品Foo创建了一个附加组件。 There are different versions of Foo, namely version 1, 2, 3 and 4. Foo有不同的版本,即版本1、2、3和4。

These versions have a mostly compatible API, but not fully. 这些版本具有大多数兼容的API,但不完全兼容。

I currently have 5 projects: 我目前有5个项目:

  • DotNetCommon - here are the common methods which could be used if I create an add-on or something other than the Foo product. DotNetCommon- 如果创建附件或Foo产品以外的其他东西,可以使用以下常用方法。
  • FooOne FooOne
  • FooTwo FooTwo
  • FooThree FooThree
  • FooFour 四四

The Foo*-projects contains the add-in for version 1-4 of Foo. Foo *项目包含Foo 1-4版本的加载项。

There are a lot of duplicated files in the Foo*-projects, as there are a lot of things in the API which are identical for all versions of Foo. Foo *项目中有很多重复的文件,因为API中有很多东西对于所有版本的Foo都是相同的。 It would be nice to separate out everything which is common for all Foo-versions. 最好将所有Foo版本通用的所有内容都分离出来。

Why not just create a common assembly for all versions of Foo called FooCommon? 为什么不为所有版本的Foo创建一个名为FooCommon的通用程序集呢?

If I would put all classes which are common for all versions of Foo into a new library project, I would still have to choose which version of Foo the new FooCommon should reference. 如果我将所有版本的Foo通用的所有类放到新的库项目中,我仍然必须选择新的FooCommon应该引用的Foo版本。 As said, they are not identical. 如前所述,它们并不相同。

Create an interface containing the common methods: 创建一个包含常用方法的接口:

public interface IFoo
{
   void CommonMethod1();
   void CommonMethod2();
}

Create an abstract base class from IFoo: 从IFoo创建一个抽象基类:

public abstract class FooBase : IFoo
{
   // Implement the common calls here
   public void CommonMethod1()
   {
      // concrete shared code goes here
   }
   public void CommonMethod2()
   {
      // concrete shared code goes here
   }
}

Create your one-off code from the FooBase: 从FooBase创建一次性代码:

public class FooOne : FooBase 
{    
   // concrete code specific to FooOne goes here 
}



public class FooTwo : FooBase 
{    
   // concrete code specific to FooTwo goes here 
}

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

相关问题 生成解决方案时,Visual Studio 2008跳过项目 - Visual Studio 2008 skipping projects when building a solution Visual Studio 2008泄漏具有200多个项目的内存构建解决方案 - Visual Studio 2008 leaks memory building solution with 200+ projects 将公共配置文件添加到Visual Studio 2008中的解决方案中的所有项目 - Adding a common configuration file to all projects within a solution in Visual Studio 2008 如何在visual studio中的不同类型的项目之间共享代码? - How to share code between projects of different types in visual studio? 您如何在Visual Studio中的项目/解决方案之间共享代码? - How do you share code between projects/solutions in Visual Studio? 如何在 Visual Studio 2022 上的单个解决方案中的项目之间共享库文件/包含文件夹? - How to share Library files/ include folders between projects in a single solution on Visual Studio 2022? 在Visual Studio 2013中的项目之间共享文件? - Share files between projects in visual studio 2013? .NET(Visual Studio)在项目之间共享资产 - .NET (Visual Studio) Share assets between projects 如何确定为什么 visual studio 在构建解决方案时可能会跳过项目 - How to determine why visual studio might be skipping projects when building a solution Visual Studio 2008解决方案中的最佳项目数是多少? - What is the optimum number of projects in a Visual Studio 2008 solution?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM