Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Adding references to .NET Core projects

$
0
0

Hi. Below is a copy of the question I initially posted on MSDN and, as suggested there, asking here.

Can anyone explain "reference adding strategy" for .NET Core projects?

Here is what I'm trying to do in VS 2015: I have a web project (MVC6), everything looks understandable there, it works. But I want to create some logic inside separate libraries and reference them in the web project.

1) Database entities library. I create a "Class Library (Package)" project and first thing I wanted to do is to addDataAnnotations reference. Initially project.json has such config:

"frameworks":{"net451":{},"dotnet5.4":{"dependencies":{"Microsoft.CSharp":"4.0.1-beta-23516",..."System.Threading":"4.0.11-beta-23516"}}}

If I use GUI in a regular way (right-click References, add reference to System.ComponentModel.DataAnnotations), it changes "net451":

"frameworkAssemblies":{"System.ComponentModel.DataAnnotations":"4.0.0.0"}

But after adding using to it, project doesn't compile: "The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) Lib..NET Platform 5.4"

By trial and error I managed to get it work by adding "EntityFramework.Core": "7.0.0-rc1-final" to the"dotnet5.4" "dependencies" section.
But why did I have to add that dependency?

2) Again about DataAnnotations. Another way I managed to project compiled was replacing "dotnet5.4" with "dnxcore50".

In this case adding "EntityFramework.Core": "7.0.0-rc1-final" worked but also"EntityFramework.Commands": "7.0.0-rc1-final" worked too.

Again I don't understand the idea behind it. Also, is it "bad" to use "dnxcore50" in Class Library?

3) Another Class Library has to work with IO and Sockets, and I need to use classes likeStream and TcpClient. And here trial and error didn't help, I couldn't add necessary references to bringTcpClient class.

Again References -> Add Reference added line "System.Net": "4.0.0.0" to "net451", but compilation gives an error: "Error CS0234 The type or namespace name 'Sockets' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) Lib..NET Platform 5.4"

So again the question is how to find correct references?

For example, inside MVC6 project I can easily get all that stuff (DataAnnotations,TcpClient) out of the box.

4) There are also more general questions that are bothering me:

What is the best practice in runtime/framework/package version selection? That "beta-23516" doesn't look nice.

And why does MVC6 project lists all packages inside separate "dependencies" JSON node, but Class Library project has "dependencies" inside "dotnet5.4"?

Thanks.


Viewing all articles
Browse latest Browse all 9386

Trending Articles