I am new to this area. I already upgraded my VS2015 with update 3. So now I have: .Net Core 1.0.0 with preview tool 2 installed.
Then I use VS2015 to create a new .Net Source project (class library). I have copied some existing .net 4.6.1 code to the new place and compiled error as expected. Then I use "porting analyzer tool"(https://learn.microsoft.com/en-us/dotnet/articles/core/porting/index) to compare and it did give some suggestion how to use the new way in .Net Core.
But there are still few class missing and cannot compile, like 'TypeDescriptor' or 'NullableConverter' etc. Then I googled and someone from Github say they already added these feature but I still not sure why I still get compilation error.
I also noticed that my class libary project has a project.json file as:
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
I foundn if I remove the 'netstandard1.6' one but change to:
"frameworks": {
"net461": {}
}
All the compilation error gone, but I could guess it's NOT .Net core project anymore, and more likely as a standard .Net 4.6.1 project.
So basically I'd like to ask:
Why developer from Github saying that is fixed already but I still couldn't find/compile those classes in my project (e.g. TypeDescriptor : https://github.com/dotnet/corefx/issues/8262)?
Some sample also puts both 'net461' & 'netstard1.6' or 'netcoreapp1.0' under 'frameworks' in project.json file. What's the purpose for that?
If I just use 'net461' for the only framework, there seems no difference to traditional .Net Framework 4.6.1 project. Am I correct?
Thanks a lot!
Install package System.ComponentModel.TypeConverter and you are good to go with .NET Core project.
For building different output (binaries) each of which targeting different platform. net461 for applications which should run on (full) .NET Framework (under Windows or Mono). netcoreapp1.0 used for app which should be run under .NET Core. netstandard1.6 (avoid using netstandard1.5 and netstandard1.6 by the way - use previous versions) used for portable class libraries, which are supposed to run under different platforms: (full) .NET Framework, .NET Core, Xamarin, Universal Windows App, etc. You may read more about here and here.
Absolutely.
Related
I have a question about .net Core project.
I have a .Net Core Project referencing other projects.
The problem is that a few projects show the warning saying that "Package 'XXXXX' was restored using .NetFramework, Version=v4.6.1.... instead of targer framework .NetCoreApp".
What kind of problems could I have?
Also can I deploy this in Linux for instance and still working fine?
warning showed
Thanks guys
Look at this thread - For a .Net Core 2.1 project, Why does Nuget restores .Net 4.6.1 packages?
What it basically means is the package you have loaded not suitable for .NET CORE, and was restored using a different version of .Net Framework.
Check if the package exists for .NET CORE (search thru NuGet Manager)
Regarding whether it will work on Linux or not - it depends on the package dependencies (e.g. if it is depending on WinForm for example, it probably won't work on Linux).
Even if it will work, I suggest finding a package suitable for .NET CORE.
I am having a weird situation where I cannot publish my final Web project. Here is the project structure:
Foo.Services.Common: this is shared library: .NET Standard 2.0.3, Microsoft.AspNetCore.Mvc.Core 2.1.0 with the class DefaultWebSettings defined.
Foo.Services.Common.Razor: Razor Class Library, has reference back to Foo.Services.Common and uses DefaultWebSettings: NETStandard.Library 2.0.3, Microsoft.AspNetCore.Mvc 2.1.0 and some other ASP.NET Core related package (static files, Configuration)
Foo.Services.Api: ASP.NET Core API only (no View, no Razor), has reference back to Foo.Services.Common. Publish well. Uses: Microsoft.AspNetCore.App 2.1.0, Microsoft.NETCore.App 2.1.0.
Foo.Services.Web: front end project. This one is the one I cannot publish! This one has references to both Common projects. Uses: Microsoft.AspNetCore.App 2.1.0, Microsoft.NETCore.App 2.1.0
However, upon publish, this one shows up:
The type or namespace name 'DefaultWebSettings' could not be found
(are you missing a using directive or an assembly reference?)
The error location is in a file of Foo.Services.Common.Razor project, NOT the Web project.
Funnily, Visual Studio perfectly works even with IntelliSense and Go to Definition:
I can build in both Debug/Release mode, run with/without debug any project in the solution well. Moreover, publishing Foo.Services.Common.Razor works without any problem!
In short: I cannot publish my Web project and have no idea what is the problem. I have tried:
Clean/Build.
Delete/Re-add references.
Manually delete all obj and bin folders.
Please show me what I may missing.
In the end, I had to remove Reference of the Common from Common.Razor and Web projects. I guess they could not build because of some conflict between .NET Standard and .NET Core. Had to copy all code of Common into Common.Razor.
I am trying to build a .NET Core application. For this purpose I create a new MVC project from the template ASP.NET Core Web Application (.NET Core).
Once I do this, I inevitably need to install some NuGet packages, and see that there are 26 updates available for my project. So I hit "update all" and get into a big mess. One was having to manually edit the project.json to make the .NETCore.App an object with {"version":"2.0.0","type":"platform"}. Now in the project.json most of the stuff is at version 2.0.0 but I get all these error messages in the Error List, and all of them say pretty much the same thing: The dependency Microsoft.AspNetCore.Authentication.Cookies 2.0.0 does not support framework .NETCoreApp,Version=v1.0
What is my missing step?
Answer came in form of comment:
VS2015 is no longer supported for .Net Core projects. You need to upgrade and migrate your project.json to .csproj too. – DavidG
I am using VS Pro Update 3
I have been following the guide here: https://www.hanselman.com/blog/HowToReferenceAnExistingNETFrameworkProjectInAnASPNETCore10WebApp.aspx
I have 3 existing .NET 4.5.1 Class Libraries, written in VB.NET but I don't think that should matter as it's all on CLR.
My ASP.NET Core project is C#, targeting .NET 4.5.1.
Here is the Framework section of my project.json:
"frameworks": {
"net451": {
"dependencies": {
"WebApp.Api.Services": {
"target": "project"
}
}
}
},
If I add all my VB.NET class libraries using Add Existing Project to my solution and try to add them as project reference, I get the following error:
Project XXX type is unsupported by current project and cannot be added
as a reference
I also tried adding a C# class Library (WebApp.Api.Services), add VB.NET references to that, then add the C# Class Library as a reference to the ASP Core project
Doing this shows the references in Solution Explorer okay, it seems as though I can use types from the C# Class library but I can't use the VB.NET library's types in my code.
I also created a NuGet package, but no luck
I have read that you can create a 'wrapper' project somehow, or Visual Studio can do this automatically.
Has anyone ever tried adding VB.Net projects to ASP Core solution?
A project built for .NET Core cannot use class libraries built for .NET Framework. They are not directly compatible with each other. In fact I'm confused when you say:
My ASP.NET Core project is C#, targeting .NET 4.5.1.
If it's targeting .NET 4.5.1, then it's not actually a .NET Core project.
You should port your class libraries to .NET Standard; that way they can be used by a wide range of compatible frameworks. It is also possible to have a class library target multiple frameworks.
I managed to solve my issue.
The guide here is correct, I had another different issue that I didn't realize.
I found a System.BadImageFormatException error which lead me to the following question Start an asp.net core project as x86 under visual studio 2015
I uninstalled the x94 version of .NET Core and installed the x86 one.
I still could not add references to the VB.NET libraries to the ASP Core project, so my C# services 'Bridge' library was vital.
In my 'Bridge' library I have Models that I can return from my ASP Controllers:
Public BridgeModelA : VB.NETLibrary.ActualModelA
{
…
}
Then extensions
Public static VB.NETLibrary.ActualModelA ToModel(this BridgeModelA)
{
…
}
Although the base members of these models cannot be accessed in the controllers, due to ASP proj not referencing the VB projs, they are returned by the controller with JSON result containing all base members.
This is actually great as it fits in with the design of thin controllers.
I want my ASP.NET Core Web API to run as a self-contained exe within the .NET framework and not .NET Core Framework. Is that possible? Thanks!
EDIT:
If I add "net451": {} to my frameworks section in project.json,
I get the following exception:
Failed to make the following project runnable: myProject (.NETCoreApp,Version=v1.0) reason: Expected coreclr library not found in package graph. Please try running dotnet restore again.
You can't create a self-contained app which targets .NET Framework >=4.5, because the full .NET Framework isn't modular and its not possible to have more than one version of it installed. Newer versions basically always replace the previous one.
Self-contained apps were one main motivation for .NET Core (together with portability)
You ALWAYS have to install .NET >=4.5 before your app can run. self-contained apps only work with .NET Core because .NET core libraries can be pulled through nuget package.
For .NET 4.6 you can only create portable apps, which is the default mode.