I've got an ASP.NET Core RC2 .NET framework web project, and I'd like to add a project reference to my regular C# class library contained within the same solution.
Using Visual Studio 2015 Update 2
File -> New Project -> ASP.NET Core Web Application (.NET Framework)
Right click solution -> New Project -> Class Library
I'm not making any of these:
Class Library (.NET Core)
Class Library (Portable for iOS, Android, and Windows)
Class Library (Portable)
Add the following to dependencies
in project.json:
"ClassLibrary1": {
"version": "*",
"target": "project"
}
Why can I not add "target":"project"
to my dependencies when specifying a project dependency?
I expect this ASP.NET Core RC2 web application (.NET Framework) to be able to reference a regular class library as a project reference.
This works
"ClassLibrary1": "*"
This does not work
"ClassLibrary1": {
"version": "*",
"target": "project"
}
How do I add a project reference to my regular class library from an ASP.NET Core RC2 web project?
If I run dotnet restore
I get a better error message on why this can not be resolved.
dotnet :
At line:1 char:1
+ dotnet restore
+ ~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Errors in C:\users\joshs\documents\visual studio 2015\Projects\WebApplication4\src\WebApplication4\project.json
Unable to resolve 'ClassLibrary1' for '.NETFramework,Version=v4.6.1'.
I doubled checked the class library targets .NET Framework 4.6.1
I've already taken a look at cannot add reference to .net core Class library asp.net core rc2, but that's for a .NET Core class library.
I also looked at Reference a Full Framework Library Project from ASP.NET Core MVC Web Application (RC2)?, but that's because the user was trying to create a web project not targeting .NET Framework. My project.json contains:
"frameworks": {
"net461": { }
},
If I right click my web project and 'Add reference' and then proceed to pick my class library, it puts the project dependency in a different part of the project.json, but it still gives me the same error message.
"frameworks": {
"net461": {
"dependencies": {
"ClassLibrary1": {
"target": "project"
}
}
}
},
You can reference:
project.json
targeting full dotnet frameworkproject.json
targeting full dotnet framework and/or CoreCLRIf your C# class library is not PCL then you can only reference it from the full dotnet section (net*
) in project.json
To reference from VS, right click on the project -> References -> Select the project
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With