0

Hi i have two projects lets say A and B, they have source files which are same, now i want that if file in one project change its reflected in another project. in simple word i want one copy for all these shared source files,

Important, these files are in different folders due to project structure i cannot put them in one common folder.

Project A
  -- Views(folder)
      -- Login.cs
      -- Stock.cs
  -- Controller(folder)
      -- LoginController.cs
      -- StockController.cs

Project B
  -- Views(folder)
      -- Login.cs
      -- WholeSellers.cs
  -- Controller(folder)
      -- LoginController.cs
      -- WholeSellersController.cs

now in above project you can see that login and LoginController is shared files but in different folders, and i cannot put them in one folder due to project folder structure limitation and also cannot create shared separate project because they cannot be build separately.

i have used Git sub-module but it create single common folder which is not my case, any other solution? please help me.

  • Create a library which is referenced by both projects and put the common files there, or this solution does not fit you? – Jakub Jankowski Oct 10 '16 at 06:55
  • Don't know about git/svn tool but I think a better option is create a third project containing the shared parts and both referring to it – Gilad Green Oct 10 '16 at 06:55
  • 2
    Are you using git or svn? You seem to have used both tags. Also, I'm not convinced that 'c#' is a relevant tag. Are you using Visual Studio? That provides ways to share files between projects. – Roger Lipscombe Oct 10 '16 at 07:00
  • "project folder structure limitation" -- explain this. "cannot create shared separate project because they cannot be build separately" -- then you have a dependency problem which you should probably also solve. Pulling shared components into a separate project (and seeing what comes with them) is a good way to start doing this. – Roger Lipscombe Oct 10 '16 at 10:41

3 Answers3

0

Consider extracting the common functionality into nuget package and install it on both projects.

Creating nuget packages: https://blogs.msdn.microsoft.com/mvpawardprogram/2016/06/28/creating-nuget-packages/

Dobromir Ivanov
  • 313
  • 4
  • 12
  • I agree on the extracting to a different project that both will use but would not put it as a nuget package. – Gilad Green Oct 10 '16 at 07:13
  • i cannot extract to different projects, because if i separate they cannot be build, and also due to limitation of project structure, i cannot change its structure, these are two winform desktop projects, i am thinking about some code management system which will manage it for me, like git – Abdullah Muhammad Oct 10 '16 at 09:22
0
  1. Create a new shared project "Project Core"
  2. Move shared code there. Controller "LoginController" and view "Login.cs"
  3. Rename "LoginController" to "BaseLoginController"
  4. Inherit LoginController in Project A and B from the "BaseLoginController"
  5. Reuse MVC Views Using a Virtual Path Provider
    Project A
      -- Views(folder)
          -- Stock.cs
      -- Controller(folder)
          -- LoginController.cs
          -- StockController.cs

    Project B
      -- Views(folder)
          -- WholeSellers.cs
      -- Controller(folder)
          -- LoginController.cs
          -- WholeSellersController.cs

    Project Core
      -- Views(folder)
          -- Login.cs
      -- Controller(folder)
          -- BaseLoginController.cs

Reuse MVC Views Using a Virtual Path Provider

Community
  • 1
  • 1
Vojta
  • 1,060
  • 13
  • 11
  • these are winform projects, and i cannot change the structure of projects – Abdullah Muhammad Oct 10 '16 at 09:23
  • Winforms? Ok. so you need to tell us what framework do you use? Winforms do not provide MVC structure out of box. Views are either forms or user controls. The closest to your case would be MVVM with reactiveUI or MVVM from devexpress. ViewModel would than act as a Controller. The idea should be the same. Create a new project core and share the views and view-models – Vojta Oct 10 '16 at 12:28
  • yes, i am using DevExpress MVVM, but i not want create other project (its lengthy task) and moving all shared code, the easiest will be if i share these files with git, so when they are change in one project other will get them – Abdullah Muhammad Oct 17 '16 at 10:01
0

Creating symbolic links to your folder and its files will solve problem i suppose.

ln -s /path/to/folderContainingFiles /path/to/symlink