I'm trying to split my .NET Core project into separate concerns using Class Libraries. I want one (or many) Class libraries and one host project. Class libraries will define the MVC Controllers and the business logic while the host project will be in charge of providing a working host. Unfortunately, the project reference refuses to work.
Let me give you the steps I took to arrive at this issue.
- Create an empty solution in Visual Studio 2015 Update 3
- Create a project of type Class Library (.NET Core) named ClassLibrary1
- Go to the project.json and modify it to make it look like the one below.
- Create a project of type Console Application (not .NET Core) named ConsoleApplication1
- Right-click in References under ConsoleApplication1 and add ClassLibrary1 as a Project reference.
- Refer to a type that exists in ClassLibrary1.
- Build the solution.
This will lead to a Build failure in the ConsoleApplication1 project with the code error CS0246: The type or namespace name 'ClassLibrary1' could not be found (are you missing a using directive or an assembly reference?). If instead of adding the reference as a Project reference I go and browse to the bin folder and refer to the dll directly, everything builds without an issue. However, this is not a solution since the Build target may change, so the path will change as well.
Code of the project.json:
{
"version": "1.0.0-*",
"dependencies": {
},
"frameworks": {
"net452": {
}
}
}
Is this a Visual Studio bug, or am I doing something wrong? I tried using netstandard1.2, net452, but the result remains the same.
EDIT I created an issue in the .NET CLI Github repository. Here is the link: https://github.com/dotnet/cli/issues/3926.