locked
sharing classes amongst two websites in a single project in VS RRS feed

  • Question

  • User2053033320 posted

    Dear Visual Studio Experts,

    I got two websites in single prokect but the classes are not visible to the other project.

    Does someone have an idea why that might be?

    I built both of them successfully.

    Neither the imports statement works nor do I see the assemblies or classes of the other project when using the "add reference" functionality.

    Saturday, March 11, 2017 9:55 AM

All replies

  • User-1509636757 posted

    I suggest to use a separate Class Library Project, this will hold all "shared" classes that going to be used in both of your application. Once you have that, just need to add Project reference of this Class Library to both of your websites in solution.

    Saturday, March 11, 2017 10:07 AM
  • User527778624 posted

    Hi,

    Implement web service (wcf) in any of the website, that will expose classes to the other website.

    Saturday, March 11, 2017 10:38 AM
  • User-2057865890 posted

    Hi Metallon,

    To add an assembly DLL to your Web site project

    1. In Solution Explorer, select your Web project.

    2. On the Website menu (for Web site projects) or the Project menu (for Web application projects), choose Add Reference. Alternatively, you can right-click the name of your Web project in Solution Explorer and then select Add Reference.

      The Add Reference dialog box is displayed.

    3. Select the Browse tab.

    4. Browse to the folder that contains the assembly you want to reference, select the assembly, and then click OK.

      Adding a reference in this way ensures that all file dependencies (debug files, XML document files, and so on) are copied.

    To add a source code file to your Web site project

    1. If your Web site project does not already contain an App_Code folder under the Web site root, in Solution Explorer, right-click the name of the project, click Add ASP.NET Folder, and then click App_Code Folder. For more information about special folders, see Shared Code Folders in ASP.NET Web Site Projects.

    2. In Solution Explorer, select your Web site's App_Code folder.

    3. On the Website menu (for Web site projects) or the Project menu (for Web application projects), click Add Existing Item.

      The Add Existing Item dialog box is displayed.

    4. In the Files of type dropdown list, select Class Files.

    5. Browse to the folder that contains the source code file that you want to add, select the file, and then click Add.

      A static copy of the selected file is added to your project. This copy is not automatically updated when the file in the folder you added it from is changed. You can now use the classes in the source code file in your Web site files. Files in the App_Code folder are compiled at run time.

    reference: https://msdn.microsoft.com/en-us/library/f3st0d45.aspx

    Best Regards,

    Chris

    Monday, March 13, 2017 3:07 AM