Search code examples
c#asp.netasp.net-coreprojects-and-solutionsclass-library

Unable to find and add an ASP.NET 5 Class Library project to a solution


I recently created a new ASP.NET 5 Web App and a standard C# Class Library only to find out that the ASP.NET 5 Web App can't reference. I did research and saw that there is an ASP.NET 5 Class Library but can't find it anywhere in my fully updated VS2015 Enterprise.

Is it called Class Library (Package) or Class Library (Portable)?


Solution

  • Yes, Class Library (Package). In fact, you can just add a project.json file with the minimum content and reference that add it to your solution by right clicking on your solution and selecting Add > Existing project....

    enter image description here

    VS will create xproj file as soon as you reference it (which is only needed for VS). Then, you can reference it like below:

    {
        "version": "1.0.0",
        "dependencies": {
            "3-class-lib": ""
        },
        "frameworks": {
            "dnx451": {},
            "dnxcore50": {
                "dependencies": {
                    "System.Console": "4.0.0-beta-23516"
                }
            }
        }
    }
    

    In this case, the 3-class-lib is the name of the class library folder which ends up being the name. You can refer to this for this sample.