Sharing code between projects RRS feed

  • Question

  • I have two projects containing a webservice and a corresponding webpage in asp.net. Both projects are written with C# code.

    It seems to me that in VC2005 the code needs to be placed in App_Code folder to be picked up and compiled. However with the increased level of code beeing shared between these projects I'd like to setup a shared path which both projects can access.

    Perhaps I'm missing something obvious but it seems that I cannot do that since the code will be outside the "default" folders and thus won't be picked up by the compiler.

    Is it possible to create a "shared" directory outside the project paths and have the projects use this code using it's compilation?

    Thanks in advance.

    -- Henrik

    Saturday, May 6, 2006 10:33 AM

All replies

  • What you have to do is add a reference to your website project, right click in the solution explorer and go "add reference" then select browse, and select your dll file.

    This will place the dll in a Bin folder and you should be able to use them.

    The App_Code folder is just for code you want to be compiled automatically.

    Edit: I may be reading things wrong, and you might have to create a .net library containing your common code and then do the above steps.
    Monday, May 8, 2006 5:00 AM
  • Thank you for your suggestion. I didn't think the best solution was that poor though.

    As you said under your "edit" I eventually have to create a library containing this. However I think it's very akward to split a single project into two. It's not going to be easier to maintain. Also you need to setup post-build steps so files will correctly be copied to their destinations. I've been trying back and forward now to find to see if there is anything I overlooked but so far it doesn't seem to be the case.

    All I want is a App_Code directory that resides in a path outside the project directory so it can be used as a shared path. How hard can that be? Don't tell me no-one tried to share code before.

    -- Henrik

    Monday, May 8, 2006 5:42 AM
  • Although I believe creating a separate binary and then adding a reference to it would be the best solution, you can do something similar to what you are asking.

    It does not work on a folder level, but on a per-file level. Right-click the project and select the "Add Existing Item" option. After highlighting the shared file you want, click the little arrow next to the open button and choose the "Add as Link" option.

    Monday, May 8, 2006 6:32 PM
  • Per file is good enough for me. I currenly only have 5 shared files so it's fine. However I could not see the option "add as link" in the dialog you mention.

    I assume you mean that the button should be present in the "add file" dialog, right? The only option I have is to add a file. Or are you talking about a normal Windows shortcut?

    -- Henrik

    Monday, May 8, 2006 8:01 PM