In VS2015 > New Project > .Net Core, there is a template for "Class Library (.NET Core)"
It wasn't until I tried to reference this library in a .NET Core Web API program, that I realized that the Class Library template is referencing .NETStandard v1.6. And my .NET Core API porject won't take it as a reference. I was trying to avoid building the library as a nuget package.
Any ideas on why a Core template isn't referencing core?
Any ideas on quick workarounds?
Update:
Opened a new "Class Library (.NET Core)", before first build I changed frameworks in project.json to
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
Then I created, in a different VS instance, a new "ASP.NET Core Web Application (.NET Core)".
I tried to add a reference to the .dll file for the new class library, now in a netcoreapp1.0 folder and I still get the same error:
.NET Core Projects only support referencing .NET framework assemblies in this release.
How to fix your problem
I was trying to avoid building the library as a nuget package.
Any ideas on why a Core template isn't referencing core? Any ideas on quick workarounds?
When you try to add the .dll as a reference for the API, your error message should say somewhere that you need to create a package in order to use that class library. It is described in the documentation.
However if you do not want to bother to make a package, for example if your class library is used now only in your API project, the easiest way is to build your class library as a Project of your Solution where the API lives. To do so, copy-paste your code in the Solution folder and include it as a project.
Some explanations about the version and frameworks
The Core template (I guess you are talking about the .NET Core API) should create a project.json with
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
}
Let's see what the lines are responsible for:
netcoreapp1.0 under frameworks means your API is targeting the framework .NET Core 1.0. That version of the .NET Core framework implements the .NET Standard 1.6 (the list here) Good thing: your Class library also use this .NET Standard 1.6. Knowing the .NET Standard 1.6 that your Class library is using make you able to choose what version of .NET Core/Xamarin/.NET Framework you can use when you later want to develop a Web app/Mobile app/Windows software for example
imports lists other frameworks/version of packages that your application can use
According to this link dotnet5.6 and portable-net45+win8 are deprecated and a netstandard version should be used instead. dotnet5.6 is still mysterious for me. portable-net45+win8 is equivalent to netstandard1.0. If you let it it means that your application can use package using .NET Standard 1.0. This can be a problem because .NET Core 1.0 starts with .NET Standard 1.6 so I would actually delete those two lines.
That being said, I am more than welcome for comments!
It seems like other answers (before this) didn't get to the point.
.NET Standard is the way forward to write .NET class libraries because it follows a set of standard APIs that can run on virtually all .NET runtimes (full framework, .NET core, Mono Xamarin...)
So if you want to write a .NET core library, you're effectively writing a .NET Standard library. No need to differentiate them. The reference to .NET standard 1.6 is to let the compiler know what to compile against.
netcoreapp1.0 is basically for .NET core console apps. A netcoreapp1.0 project will compile to dll that can be executed (contains program entry like static void Main())
So it makes sense why you can't have that in a library :)
Related
I am building an MVC Web API (Service) with Views returned in specific cases. As an architectural decision, I've been directed to NOT build the service project in .NET Framework 4.*. Rather, I am to attempt .NET 5.0 first, and then Core 3.1 if 5.0 doesn't work.
This service project in my solution will depend on a few class library projects, call them DataLibrary, ComplexLibrary, and DocLibrary. DataLibrary will depend on a Nuget package of Oracle, be it ODP or Oracle Managed Data, in order to query an Oracle database via an Oracle Package on that database. DocLibrary will depend on a Nuget package of Aspose Word & Aspose PDF. ComplexLibrary will depend on Oracle AND Aspose.
Here's my dilemma:
Aspose Word's latest stable release (21.6) will report that it is compatible with 5.0 and Standard 2.0, but not .NET Core.
Oracle Managed Data reports that it is compatible with Standard 2.1 or Standard 2.0, but not 5.0 or .NET Core.
My own libraries have reported that they are not compatible with my API .csproj if...
3a. The API is 5.0 and the libraries are .NET Core or .NET Standard
3b. The API is Core 3.1 and the libraries are .NET Standard.
Since my compile script naturally requires a run of Nuget to retrieve all the necessary dependencies, I cannot get a clean compile because I seemingly have no combination of versions for my WebAPI and libraries that satisfy each others' compatibility needs. Since Standard libraries are the only common .NET version that satisfy the needs of both Aspose & Oracle, What available version for my WebAPI (i.e. I don't believe that Standard is an option for anything other than a class library) is compatible with .NET Standard libraries?
Thanks.
Please see the following article https://learn.microsoft.com/en-us/dotnet/standard/net-standard.
.NET Standard is not a framework it is kind f specification and .NET Core, .NET 5, Mono framework etc are .NET Standard implementations.
So for library projects I would select .NET Standard and for the service .NET Core or .NET 5 (which is actually the next version of .NET Core)
Well, don't I feel silly.
Turns out, the issue wasn't incompatibilities within Aspose, Office, .NET Core, 5.0, and Standard, but a failure of a prior version of NuGet to handle the different versions.
While my VS 2019 install was able to compile the whole solution effectively, my local install of NuGet was not. This was due to VS2019 likely using the most up-to-date version as of this post (5.9.#), while my locally installed version was 4.9.#. Thus, VS was able to sail through while my compile script kept failing at the NuGet stage (which I have included prior to the actual compile.) Once I ran a NuGet update, everything was good to go.
Long story short: KEEP YOUR NUGET VERSION UP-TO-DATE!!!
I have multiple class library projects targeting .NET Framework 4.7.2. I want to upgrade to .NET 5. In the project properties I only see versions of the .NET framework, I don't see .NET 5. I know I could open the project as a file and modify the target framework but what is the correct way of doing it with the UI?
Microsoft provides here a good migration example. You can also check this post with another example.
If you intend to do this gradually, keeping common packages compatible with both .NET Framework and .NET 5, you may use .NET Standard projects/packages for that.
I created a new .net core 3.1 project and built it using VS2019 16.4.4
Now I want to change it to .Net Standard.
I know to go to the project properties and select the Target framework combo.
However no Standard framework options appear.
If I select Install other frameworks then I am taken to The download .Net SDKs for Visual Studio page
However the SDK I want is already installed on my machine.
Why am I not seeing what I want in the combo box.?
.NET Standard, like .NET Core and .NET Framework, is separate framework, so you can't switch that easily. You would need to create separate project targeting .NET Standard. Once you do it, you will see other options in 'Target framework'.
Worth to mention, you can't reference .NET Core and .NET Framework projects from your .NET Standard library, since .NET Standard is just an abstraction which is built differently depending on the executing environment (.NET Core or Framework)
I have a C# project which was created using NetFramework 4.6. I want to convert it to using the NetCore 2.1.
I checked the network, and people say I can just change the Target Framework value in the project's properties page. But on my computer, I cannot see options for NetCore.
I already have the NetCore 2.1 SDK installed.
Is there another way to convert the project? Is there something wrong with my project that prevents it getting converted?
People are wrong, there is no such "one step" approach.
Remember that .NET Core is not a higher version of .NET Framework, it is rather a rewrite from scratch. So it does not work like retargeting .NET Framework version form 4.0 to 4.5.
Porting to .NET Core from .NET Framework is a good place to get started.
Edit: This page lists some differences between .NET Core and .NET Framework.
You can't do this simply like this; because of their totally different frameworks, not different versions of same framework. You have to port your project to .net core; there is one of the nice extension for visual studio that generate a report for you about how portable your code is between .NET Framework and .NET Core.
This is also one of the article about the issue that may be useful for you.
I have one PC with Microsoft Visual Studio Community 2017
Version 15.2 and it has a project template for Class Library (Portable).
Another PC with Version 15.3.1 has a template for Class Library (Legacy Portable). Are PCLs now legacy ?
Any current news on what I should be using instead ?
Well, "should", I won't say that without seeing exactly what you're doing but yes, PCLs are now "legacy", the new way is .NET Standard and .NET Core.
Please note that legacy does not mean "will stop working" so there shouldn't be a need to do anything as of yet.
To figure out which kind of .NET Standard version you want to target to get-out-of-legacy, you can consult the compatibility list on the .NET Standard web page.
Specifically, you likely want to consult the other matrix on the same web page, the .NET Implementation Support matrix and figure out which platforms you want to target, then create a "Class Library (.NET Standard)" project targetting the highest .NET Standard version you can get away with.