What is wrong with my class library reference in an MVC 6 Web Api project? - asp.net

Working in VS 2015 Community, I've created a Services class library project, targeted at .NET 4.6. Now, in my main Api project, all references fall under DNX 4.5.1 and DNX Core 5. When I add the reference to Services, I get the compiler error :
Dependency Services >= 1.0.0-* could not be
resolved Api C:\Development\Surveys\src\Api\project.json
What do I have to do to make my class library compatible with the Api project?

Both of your projects have to target DNX Core 5 if your main (Api) project supports it
You can't reference .net project that has higher version than source one. So both of your projects should target 4.6
The way you described the problem I'm not sure if Services is normal (let's call it old) Class Library or ASP.NET 5 Class Library. If it is old then your main project can not target core clr. Just remove this TFM from project.json.

Related

Why mix .Net Standard and .Net Core projects in one solution?

I just started working through the Apress "Building Web Applications with Visual Studio 2017". I am at the beginning setting up the projects.
So I set up a solution called SpyStore.
Then a .Net Core console app called SpyStore.DAL.
Then a .Net Standard Class Library project called SpyStore.Models.
My question is why would the author choose .Net Standard class library over .Net Core Class library. Is there a difference?
What is the difference between .Net Standard and .Net Core.
And could there be a reason for him mixing Standard in all of the sudden?
You can visualize .netstandard as a set of APIs. It is implemented by multiple runtimes, like netframework (net461, net47 monikers for example) or netcore (netcoreapp) A lib is not an executable, so it is independent from the concrete implementation.
Because you may want to use your library in a .net framework project (or any other implementation of .net standard), targeting netstandard make sure it is fully portable to any of these implementation, where a netcoreapp lib would only be targetable from a netcoreapp project.
An app can only be netcoreapp or netcore, as it is dependent of the implementation of the framework
You can find more infos here, and which platform implements which version of netstandard:
https://learn.microsoft.com/dotnet/standard/net-standard

Why does Visual Studio 2017 target netcoreapp when creating a new Class Library project

From this post on stackoverflow:
"If you are building a library (to be consumed by another library or application), you'll target netstandard1.X"
"If you are building an application (console, UWP, ASP.NET Core web app), you'll target netcoreapp1.0"
However when I create new .net core class library project in Visual Studio 2017 I see this:
<TargetFramework>netcoreapp1.0</TargetFramework>
Why does a class library target netcoreapp?
In the New Project wizard you should select .NET Standard from the left tree.
After creating project I get this:
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>
I have no idea why there is also a similar project in .NET Core section and its purpose but for most cases .NET Standard is right choice for Class Library projects.

How to add project reference to ASP.NET Core 1.0 MVC project

I have a ASP.NET Core 1.0 MVC app in solution X and I have some common projects (.net 4.5.2 class libs) in solution Y.
I want to reference the projects in solution Y from my app, when I do so via add reference -> Browse .. I get:
.NET Core projects only support referencing .NET framework assemblies in
this release. To reference other assemblies,
they need to be included in a NuGet package and reference that package.
I then created a nuget package of those projects, added the folder that contains the nuget packages as a repo source and loaded the projects. This adds the projects successfully to my project.json, but 'nothing' else actually happens, I still can't use the code in my app.
Now ASP.NET Core is past its beta status, what is the official way of dealing with this?
Many people have struggled with this issue and there is a long running thread on GitHub about it. Even the people using the latest RC3 build are reporting the same problem that you are having.
The only way I've been able to reference class library projects in an ASP.NET Core web application is to create both the web application and the class library projects in Visual Studio 2015 Update 2. And they all have to target .NET Framework 4.6.1.
I had to copy the code from my old class library projects to the new ones. But in the end I think I saved myself time by not having to mess with all the workarounds that don't seem to work for a lot of people.

Can I use a .NETFramework project within a .NETCoreApp project?

I am building out a website using WebAPI in .NETCoreApp v1.0. However, I am trying to connect to an API for blackbook which is in another project that is built in .NETFramework v4.5.
When I attempt to add a reference to it in Reference Manager I get the following error:
The following projects are not supported as references:
BlackbookWCFProxy has target frameworks that are incompatible with targets in current project MainProject.
MainProject:
.NETCoreApp,Version=v1.0
BlackbookWCFProxy:
.NETFramework,Version=v4.5
So does that mean I have to scrap my entire project because a single API was built in .NETFramework? What about the other APIs I want to use? How can I get it to work nicely with my project?
You should install .NET Core RTM to make a .net core project so you will find this on following link

Class library that can be shared between .NET Framework and .NET Core

I have a big class library written in .NET 4.0 but when I reference it in a Store App that uses .NET Core, it shows an error. And further, Microsoft just released .NET Core for the next version of .NET.
I want to know what type of project will be able to be shared by both .NET 4.6 and .NET Core? Is a class library able to do that?
It seems that the release of .NET Core specialized for Store Apps causes confusion for me.
If you have a PCL (Portable Class Library) that works for Metro apps, it will definitely run on the fully fledged .NET (aka, your normal ASP.NET, WF, WPF applications).
That means that you don't have to do anything, besides porting your existing library to be compatible with the PCL you choose.
There is a new target called dotnet which you can use to target the platforms DNX, UWP and .Net 4.6. Effectively, this libraries are build against .Net Core packaged libraries instead of the libraries of the full .Net Framework.
Read more here: https://oren.codes/2015/07/29/targeting-net-core/ and related posts.

Resources