What happened to IHtmlContent? - c#

I'm getting ready to update a library to work with ASP.NET Core 3.0. My library provides an implementation of IHtmlContent, which used to live in the Microsoft.AspNetCore.Html.Abstractions package.
That package seems not to have been updated with the release of .NET Core 3.0 — it's still at version 2.2.0 and hasn't been updated in nearly a year. I can't find any documentation for IHtmlContent in the .NET API Browser for version 3.0 either (either by switching the dropdown from the above link to "ASP.NET Core 3.0" or by searching for it).
Where did IHtmlContent move to? Am I meant to continue using the one from the Abstractions package? Where are the docs?

Related

Using the preview versions of asp.net core mvc in a class libary

I am making an ASP.Net Core MVC app which handles multiple subdomains. Therefor I want to split up all Views/Controllers by their subdomain in a different project. What I am currently struggling at is referencing the latest pre-release of the ASP.Net Core framework in a .Net Core 3 Class Libary.
Now I do not know which nuget package I need to reference, in order to be able to have all the libraries needed for Controllers and Views.
I suspected that the Microsoft.AspNetCore.Mvc nuget package would be all I need, but it is version v2.2.0 instead of the pre-release one e.g. 3.0.0-preview9.19423.6.
In ASP.NET Core 3.0, MVC is part of the Shared Framework. The Microsoft.AspNetCore.Mvc package is one of many that will no longer be published separately.
To simplify the way in which consumers target and use the ASP.NET Core shared framework, we will stop producing many of the NuGet packages that we have been shipping since ASP.NET Core 1.0. The API those packages provide are still available to apps by using a <FrameworkReference> to Microsoft.AspNetCore.App. This includes commonly referenced API, such as Kestrel, Mvc, Razor, and others.
Reference: Breaking changes to Microsoft.AspNetCore.App in 3.0

How to Upgrade to ASP.NET Core 2.0

I have an ASP.NET Core project. It is .NET Framework based. I have been working with .NET Version 4.6, but am happy to upgrade to 4.6.2 or 4.7. I have both installed on my machine. The referenced NuGet packages are numerous and version numbers varied. But, it seems that roughly speaking, I am using version 1.1.3 of ASP.NET Core.
I want to upgrade to the latest version of ASP.NET Core and ASP.NET Core MVC but every time I try, I get this error message:
Could not install package 'Microsoft.AspNetCore.Mvc.Core 2.0.0'. You
are trying to install this package into a project that targets
'.NETFramework,Version=v4.7', but the package does not contain any
assembly references or content files that are compatible with that
framework. For more information, contact the package author.
After Googling for this, I came across this disconcerting Github thread:
https://github.com/aspnet/home/issues/2022
This seems to imply that at some point, V2 was not supported by the .NET Framework. I read through the thread to some extent, but these words from another user basically some up my thoughts on the subject:
I really don't know what is happening. Why do have many dotnet this
and that. This is really crazy. How do we have keep tracks of this?
No proper documentation on migration from one to another.
The OP was edited to say this:
Edit: the "no .NET Framework support for ASP.NET Core 2.0" plan has
been officially cancelled and running ASP.NET Core 2.0 on .NET Desktop
will be supported in the next previews. For more information, read
Announcing ASP.NET Core 2.0.0-Preview1 and Updates for .NET Web
Developers or watch .NET Standard 2.0 and .NET Core 2.0.
I guess that means that Microsoft planned to fix the problem at some point. But, what I can't work out is whether or not Microsoft have actually fixed this problem.
Is anyone running ASP.NET Core on .NET Framework? Which .NET version? How did you get it working?
As per #Melbourne Developer's suggestion:
Make sure you download the latest .Net Core 2.0 installers.
Create new ASP.Net Core Web Application
Choose .NET Framework from dropdownlist in wizard and ASP.Net Core 2.0
Copy content over to new project. Fixing up all namespace issues/compilation errors

Combine ASP.NET and ASP.NET core in the same solution

I am creating a solution using ASP.NET Core 1.1 (SDK 1.0.4) and I require to use System.DirectoryServices namespace.
According to this Github issue
they are porting those APIs from the .Net Framework in the upcoming 1.2 version. However, I have seen that you can create an ASP.NET Core app targeting the full .Net Framework. I have follow some tutorials but all of them seem to be outdated (.Net Core 1.0 using project.json) and I have found no way to make it work.
In the same manner, I have seen some Github projects that seem to run ASP.NET Core and System.DirectoryServices namespace using something called DNX (like this one ). However, this project also fails in Visual Studio 2017.
Is there any real solution to have access to System.DirectoryServices on ASP.NET Core?
There might be a hacky way to go about it, but I haven't explored this enough, yet. I have noticed that when you create an "ASP.NET Core Web Application (.NET Core)" project, it doesn't allow you to change the .NET framework version to anything but available .NET Core versions. You'll need to create an "ASP.NET Core Web Application (.NET Framework)" project in order to use the full framework.
If you've already got an existing project you're working on, the best thing I can recommend is to simply create a new "ASP.NET Core Web Application (.NET Framework)" project and migrate your existing code over to that. For the most part, it should just be copy-and-paste. Like I said, there might be some other way, that I just don't know, but you at least have that method.
FWIW, DNX was .NET Core, before it was ".NET Core". There was a somewhat similar setup where you could run DNX on full .NET or just the "core" .NET functionality. It doesn't really help you here.

How do I reference a .NET Framework project in a .NET Core project?

I'd really like to start using .NET Core and slowly migrate applications and libraries to it. However, I can't realistically upgrade my entire code base to use .NET Core and then go through the process of testing and deploying a plethora of applications in production.
As an example, if I create a new .NET Core application and try to reference one of my .NET Framework projects I get the following:
The following projects are not supported as references: -
Foobar.NetFramework has target frameworks that are incompatible with
targets in current project Foobar.NetCore.
Foobar.NetCore: .NETCoreApp,Version=v1.0
Foobar.NetFramework: .NETFramework,Version=v4.5
Is it possible to create a new .NET Core application and reference my existing .NET Framework libraries? If so, what's the process for doing that? I've spent hours going through Microsoft's documentation and searching their issues on GitHub, but I can't find anything official on how to achieve this or what their long-term vision is for this process.
Old question, but with the release of .NetStandard 2.0 and .netcore 2.0 and vs2017.3, the game has changed.
You can use the Full .NET Framework (TFM) with .NetCore 2.0, but how?
In Visual Studio 2017.3, you can reference the Full .NET Framework (any version) directly from within a .NetCore2 project.
You can build the .NetStandard2 class library and reference your TFM. Then reference your .NetStandard2 library from your .NetCore2 project.
For example, referencing json.net net45 from .NetStandard2.
Browse to the folder and select version net45 (not netstandard1.3)
See the dependency in the image below, no yellow warning as you see.
Even if a Nuget library is not ready to be ported to .Netstandard 2, you can use any API in the library that is compliant to net461.
Quoting for the .NET Core 2/Standard 2.0 announcement with links:
.NET Core 2.0 is able to freely reference libraries that have been built for .NET Framework up to version 4.6.1
However, some libraries may fail at run time if they try to use API methods that aren't available on .NET Core
Reference: .NET Core App target .NET framework 4.5.2 on Linux
A need to use third-party .NET libraries or NuGet packages not available for .NET Core
So only in cases where the libraries or NuGet packages use technologies that aren't available in .NET Standard/.NET Core, you need to use the .NET Framework.
Reference: Choosing between .NET Core and .NET Framework for server apps
You can now reference .NET Framework libraries from .NET Standard libraries using Visual Studio 2017 15.3. This feature helps you migrate .NET Framework code to .NET Standard or .NET Core over time (start with binaries and then move to source). It is also useful in the case that the source code is no longer accessible or is lost for a .NET Framework library, enabling it to be still be used in new scenarios.
Reference: Announcing .NET Core 2.0
Yes, we are currently attempting the same thing. The trick is to make sure that you are supporting the same .NET frameworks. Inside your project.json file, make sure the framework matches the framework of the project you wish to include. For example:
"frameworks": {
"net46": { --This line here <<<<
"dependencies": {
"DomainModel": {
"target": "project"
},
"Models": {
"target": "project"
}
}
}
},
FYI: You might need to change the framework of your .NET Core or your older projects to achieve this. .NET Core can be changed just by editing the project.json file as seen above. You can so the same in .NET projects by right clicking the project and opening properties. Change the framework level there.
Once you have matched the two project frameworks then you should be able to include them. Good Luck!
We delayed migrations as long as could as it seemed daunting as first. But we got an insistent client who wanted to migrate ASAP.
So we migrated their Fintech Web App developed on .NET Framework 4.8 Web Forms to .NET 6 Razor Page. Our team scoured though hundreds of online resources & spoke to Microsoft Tech Support before we started the project. Hope the high-level walkthrough of our journey help you plan your migrations.
Our .NET Framework Website consisted of 1 .NET Web Forms project and 12 Class Libraries.
Here is how we did it.
Refactored the .NET Framework 4.8 Web Forms code
We ensured that the Web Forms code behind did not have a single line of service or business logic code. When we did find some business logic code in the web forms code behind, we refactored it, by moving it to the class libraries.
Created new .NET Standard projects
We created a new .Standard 2.0 Class library project for every .NET Framework 4.8 Class Library. If the original project was called "FintechProjectName.StockMarketClient", we named the .NET standard project "FintechProjectName.StockMarketClient.Standard".
Copied all files from .NET framework to .NET standard
We copied all the class files from .NET framework to .NET standard projects. We then removed all the .NET framework class libraries from the solution and added references to the new class libraries. All projects compiled on the 1st try itself and all our test cases too passed with minor changes.
Create new .NET 6 Web App Project
We created a new .NET 6 Web App Project. We had to entirely redo the front-end as there is no direct path for migrating Web Forms to Razor Pages. This was the only project which took us about 1 month to migrate.
Reference .NET standard class libraries in the new .NET 6 website
We copied all the .NET Standard libraries to this new solution containing the Razor Pages web site. Added the references and got it to work.
Move from .NET Standard to .NET 6 class libraries
Once the new website was up and running, with all test cases passed, we did the last step in the process which was the simplest. Created .NET 6 class library projects for each of the .NET standard libraries and named the projects appropriately. Copied all class files from .NET standard projects to their corresponding .NET 6 projects. Then we removed the .NET Standard libraries and added references to the new class libraries.
Overall project timelines were about a month and a half, most of it spend on Razor Pages implementation using the same html design.
Note:
If you are using any 3rd party library which does not have a .NET standard or .NET 5 version, then you are out of luck. You will need to find a replacement nuget package and recode your application to use this new library.
In my case with .net6 referencing framework 4.8 library ( both winforms), the trick seems to be to add the reference to the framework dll as a shared reference.

The dependency Twilio in project does not support framework DNXCore, Version=v5.0

I'm interested in figuring out how to use the Twilio API, and I am building an ASP.NET 5 application using the Twilio API with MVC6 (trying to follow this tutorial). So far, I have created an empty ASP.NET 5 application, and I added "Twilio" to the dependencies in project.json. I get the following error:
"The dependency Twilio 4.0.3 in project TwilioTest does not support framework DNXCore, Version v5.0"
I notice that when I remove "dnxcore50" from "frameworks", the error goes away.
I'm not sure what this means or how to approach it. I'm still pretty new to .NET and trying to wrap my head around how all of the pieces fit together. Does it mean that Twilio isn't compatible with DNXCore? Since all I want to do for now is learn how to use Twilio, could I essentially remove the dnxcore50 framework from the project and continue working through building the app?
The Twillio NuGet package is dependent on the full .NET stack, which in project.json frameworks terms is DNX451. What that means is, you can add the Twillio NuGet package and remove the DNXCORE50 reference and your project will run as expected and you will be able to use the Twillio API. As far as I know the only major drawback is that your ASP.NET Core project will no longer be cross platform as you are now dependent on the full .NET Framework stack which is only present in Windows.
In a nutshell, you should be fine unless you are planning to deploy to Linux/OSx. Hopefully as ASP.NET CORE becomes mainstream more 3rd party SDKs will be built to require only DNXCORE50 as a dependency.
Another option don't use the Twillio Libraries and code against their REST API. See documentation here: https://www.twilio.com/docs/api. But I wouldn't recommend this if you are deploying to a Windows environment.
Twilio is working on their .Net Standard (Core) library. In the meantime, I've published a .Net Core port of their library to unblock our current projects until we get the official update. Feel free to take it for a spin:
Install Twilio.NetCore from Nuget.
And you can check out the source on Github.

Categories

Resources