aspnet core 1.0 rc2 EntityFramework 6 - asp.net

I am looking to start a project and I would like to use EF6 with my aspnet core 1.0 rc2 project. The EF6 project is a .net46 project. In trying this out, I keep getting errors in my project.json saying something about the projects are not compatible (net46 and netcore 1.0 or so). I changed the settings in my project.json and added the full clr .net46 to get to these errors. The manual's explanation about rc2 specific instructions doesn't go far enough for me So I was hoping if anyone has been able to get this scenario working and if they would share what they know.
Thanks

You need to use only full dotnet framework in your project.json like this:
"frameworks": {
"net451": {}
}
In this case every classic dotnet library should work.
Hope it helps.

Related

Problem referencing transitive dependencies when building a specific .NET Core project in TeamCity

I have a solution with multiple projects, the notable projects are:
ContractProject
DataProject
WebProject
WebProject is a .NET Core project, the other two are .NET Framework.
This is the file structure, including the csproj and sln files:
DataProject references Dapper, which is a NuGet package.
When attempting to run the build configuration in TeamCity, I get the following (slightly reduced, redacted) error:
DapperWorklistRepository.cs(4,7): error CS0246: The type or namespace name 'Dapper' could not be found (are you missing a using directive or an assembly reference?) [REDACTED_PATH_TO_DATAPROJECT_CSPROJ_FILE]
......
Build FAILED.
......
Process exited with code 1
Step Build (.NET Core (dotnet)) failed
This is my only build step (.NET Core):
Any idea what I'm doing wrong? I have a feeling it may be something to do with the web project not being able to reference the projects one level back? I have tried setting the required paths in many different ways with no avail.
I ended up figuring this out, implementing a bit of a hack of a solution.
The problem lies in the fact that I'm referencing .NET Framework projects from a .NET Core project, and attempting to build them all in one step.
The work around required two things:
Firstly, I had to include a NuGet installer build step. I couldn't figure out how to target specifically .NET Framework projects (it doesn't support .NET Core), so I essentially duplicated the solution file, renamed it to NetCoreBuildHelper, and deleted the Web project reference. The reference remained in the original solution. I then referenced the new NetCoreBuildHelper solution in the NuGet Installer.
Secondly, I had to create a .NET Framework MSBuild step, which built the other projects (DataProject and ContractProject), referencing the NetCoreBuildHelper solution.
I'd love to hear responses to this if I could improve the solution, as it feels like a bit of a hack
This question is on the older side - but I'm interested in knowing if you arrived at any more information.
To the best of my knowledge, .Net Framework and .Net Core are fundamentally different platforms, so they are not meant to be referenced by one other. .Net Standard projects however, are intended to be a vehicle for code sharing that both .Net Core and .Net Framework can reference, as long as the Standard version being targeted is the correct version. For example, .Net Framework 4.8 is, at most, .Net Standard 2.0 compatible. If the .Net Framework projects were class libraries, it might be worth migrating those to be .Net Standard projects, and reference them from your .Net Core project.

.net Framework to .net Core

Im doing a project with .net Framework , but to run on the linux i need .net Core..
I heard that it is possible to change .net Core to .net Framework only with changes on the project.csproj with this:
<TargetFramework>netcoreapp1.1</TargetFramework>
to
<TargetFramework>v4.5.2</TargetFramework>
and i tried to do the opposite , but i got some erros on the project...
There's a way to do that?
Thanks!
You can not switch a .NET Framework project to .NET Core that easy.
You might change an empty project but not one you already started coding.
Possibly you'll need to rewrite or start from scratch.
There are some major differences between two
Format of configuration files (web.config vs appsettings.json)
See this post on providing backward compatibility for App.config, appSettings.config and Web.config XML-based configuration providers
Used libraries
Startup files (Global.asax vs Startup.cs)
Lack of static objects in .Net Core. Like Session and Application objects -
which is a good thing btw.
Many of the .Net Framework libraries are dependant on
app.config/web.config files

How to create a .NET Core library I can reference from a .NET Core App (Web API)

I'm working in Visual Studio 2015 Update 3 and .NET Core 1.0. I have a Web API project which is of type .NETCoreApp v1.0. When I add a .NET Core class library, it is of type .NETStandard v1.6. I can add this library to the Web API project as a reference, but it is not recognised when I try to add using statements.
If I create another project of type .NETCoreApp, I can reference it and use the classes without a problem.
How do I make use of a .NET Core class library from my .NET Core App?
Edit/Update:
This appears only to be an editor/Intellisense issue, because despite the editor warnings, the .NETCoreApp does build and run, calling into the class library.
I am running Resharper, which I see is blamed for similar problems with other types of projects: I have checked that I have the latest version and have cleared the Resharper cache and restarted VS2105.
This is a Resharper issue. At this time Resharper (v2016.1.2) does not support .NET Core 1.0.
There are 2 possible solutions:
Uninstall Resharper, and the Visual Studio native intellisense works.
Install the Resharper 2016.2 EAP (Early Access Program) version. I've done this and it's working. Obviously it comes with the caveats of any EAP/beta product.
Here is a link to the Jetbrains forum post where I was told .NET Core 1 was not yet supported and pointed to the EAP version.
Once you've built a library that targets netstandard1.X, you can either:
Produce a NuGet package with dotnet pack and host it locally or on NuGet. Then, install it in your netcoreapp project as any other dependency.
If your library and application are part of the same solution, make a local reference:
project.json
"dependencies":{
"MyLibrary.Core": {
"version": "1.0.0",
"target": "project"
}
}
target: project tells dotnet to look in the current solution for the dependency, instead of using your NuGet feeds. Again, this only works if you are developing the library and application in the same solution.

Referencing a .NET Core class library in a ASP.NET 4.6 MVC App

I think that I am fundamentally missing something here and I apologise for stupidity in advance. Trying to embrace the new world of dotnet core and working on a project as a way of trying to learn.
I have written some authentication middleware to work for with ASP.NET Core Identity. I have used a .NET Core Class Library for the middleware - the advantage being that I believe I can then potentially target any framework as well as build Nuget packages of my component. The middleware works fine when used with an ASP.NET Core Web app targetting .NET Core - based on the VS2015 RC2 template.
Feeling adventurous I decided to create a version of the component based around OWIN/Katana authentication middleware so I could use it with ASP.NET 4.5/6 web applications. Instead of creating a traditional class library project I once again used the .NET Core Class Library template but targetted it only at .NET 4.6, i.e. net46. It compiles fine but I cannot get my ASP.NET 4.6 application to reference it. I followed the information in this SO question to create a NuGet package, create a local source and then try to add it to my ASP.NET 4.6 project but it fails with the error:
Unable to resolve dependency 'NETStandard.Library'. Source(s) used: 'nuget.org', 'AspNetRc2Source', 'MyGet', 'Local', 'Microsoft and .NET', 'Microsoft Visual Studio Offline Packages'. 0
My head is spinning with dependencies and frameworks.
Anyway here is the project.json file in my .NET Core class library - you can see it is only targeting .NET 4.6 which is what my ASP.NET app is targeting too.
I feel I need some serious .NET 101 course to get my head around how all these dependencies fit together, but if anyone is kind enough to point me in the right direction it would be appreciated.
Remove the reference to NETStandard.Library and it should work. You don't need that if you're only targeting .NET 4.5+.
I work on an OWIN middleware library that can be consumed from both .NET 4.5+ and .NET Core. I target both using a project.json that looks like this:
"dependencies": {
"Stormpath.Owin.Abstractions": {
"target": "project",
"version": "1.0.0"
}
},
"frameworks": {
"net45": {
"frameworkAssemblies": {
"System.Collections": "4.0.0.0"
}
},
"netstandard1.3": {
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027"
}
}
}
Since only .NET Core (netstandardX.Y) requires .NETStandard.Library, it's listed as a dependency for only that target, not as a general dependency. The project will happily build for .NET 4.5 and dotnet pack produces libraries that install perfectly on both platforms.

How do I create a ASP.NET project based on the .NET Core, not on the full Framework?

I was reading all about .NET Core after hearing about it for months. I got Visual Studio 2015, so I thought I would try it out. I go into File - New Project, choose ASP.NET Web Application, and see I can only choose a version of the full .NET Framework (such as 4.6). How do I create a ASP.NET project based on the .NET Core, not on the full Framework?
I thought there would be some tutorials on this, but I can't find any. All I see is based on the full Framework.
ASP.NET 5.0 Core beta5 shipped with VS 2015 RTM. Beta6 just shipped and be used to upgrade VS 2015. (Read the Install Instructions!)
When you create a project from one of the ASP.NET 5 Preview Templates (Empty, Web API, or Web Application) it is set up to compile both Core and 4.5.1 Framework versions every time you build.
To change this to build only Core, do the following:
Project / Properties / Application: change Platform from .NET
Framework to .NET Core
Open project.json and find the "frameworks" section. Delete
"dnx451": {}, and save.
Build
You are now running on the CoreCLR.
You can find the .net core and nightly builds at:
https://github.com/dotnet/core
https://github.com/dotnet/coreclr
Thanks for the comments and whatnot guys... Can't delete my answer since it's accepted, so here's some screenshots showing how to get to the new template. Note that the new framework version is not listed where you (at least I) would expect. You can choose the asp.net 5 tempate after you actually choose to create a web application in one of the (non 5.0) framework templates.

Resources