Using the same modules in multiple projects

前端 未结 3 950
失恋的感觉
失恋的感觉 2021-01-05 13:47

I\'m using Visual Studio 2010 and coding in VB.NET.

My problem is that I\'ve collected all the modules I\'ve written and intend to reuse and placed them in a separat

相关标签:
3条回答
  • 2021-01-05 14:32

    You're definitely on the right track in trying to minimize code duplication! The best thing for you to do is compile your code into a reusable class library that you can use from multiple projects.

    1. Create a new "Class Library" project in Visual Studio.

    2. Move all of your modules into that project.

    3. Compile that project, and note the location of the DLL file that is generated.

    4. Add a reference to that DLL file to each of the other projects that you wish to be able to call methods exposed by your modules.

    The benefit of this method over adding your individual code files to each project is that if you ever update or modify the code in the class library, all you'll have to do is recompile the class library.

    Additionally, if you plan on deploying several different applications that rely on the same modules, this will allow each of them to dynamically call the methods exposed as part of the class library.

    0 讨论(0)
  • 2021-01-05 14:33

    You can move the modules to a separate, central library project which can be included in each solution of your projects.

    In each project you can add a reference to that library if you want.

    0 讨论(0)
  • 2021-01-05 14:45

    The Solution offered by Marcel J. Kloubert is the better one. (because in the setup you described its too easy to accidently break functionality.)

    But you can do what you asked for by:
    1) right click your project
    2) choose Add -> Existing item
    3) select your file
    4) click on the little thingy right next of Add
    5) choose Add as Link

    0 讨论(0)
提交回复
热议问题