. NET Core 2.0 learning Note (iv): Migrating. NET Framework Engineering to. NET Core

Source: Internet
Author: User
Tags emit unsupported

In the process of migrating. NET core, the first step was to change the target framework of the. NET Framework project to. NET core2.0, but the official website did not provide a conversion tool, which required us to do it ourselves. NET Framework Engineering Migration There are basically two scenarios for core engineering:

1. Create a project for. NET core and move all the files over. This is a more stupid way, if the project is relatively small, fortunately to get. If there are hundreds of works, then cry.

2. Force the project to migrate to. NET core by editing the. csproj file.

What we are sharing today is how to migrate. NET Framework engineering to. NET core by modifying the. csproj file.

Step one: Open the. NET Framework solution through VS2017, after uninstalling the specified project, open the. csproj file.

Step Two: Remove two import references

Step three: Remove the configuration information for Release, debug compilation

Step four: Modify the project node properties:

<project toolsversion= "15.0" xmlns= "http://schemas.microsoft.com/developer/msbuild/2003" >

To be replaced by:

<project sdk= "MICROSOFT.NET.SDK" >

Step Five: Remove targetframeworkversion information and add information:<targetframework>netcoreapp2.0</targetframework>

Step Six: Reload the project

Step seven: on the. NET core project that is already loaded, continue editing the csproj file.

Step Eight: Remove the file list information.

Step Nine: Remove the AssemblyInfo.cs file.

Step Ten: Remove the hidden files from the. NET Framework project. Because the. NET core project does not support the exclusion of files, after completing the above migration, the original hidden files are automatically added to the project, the junk files, please identify, manually delete.

Step 11: Re-add the NuGet package reference. The. NET Framework's reference information to the NuGet package is stored in packages.config. This file has been removed in. NET Core. Please re-add the NuGet references in your project based on the Packages.config information. The reference information is automatically added to the csproj file.

Step 12: Compile the project. To say, many of the. NET Framework APIs are not already in. NET core, and before migrating, take a look at the following. NET core data.

======================================

1. Serialization and XML operations are not supported

* (Required: Install-package System.Xml.XmlDocument, Install-package System.runtime.serialization.formatters-pre, Install-package System.Xml.XmlSerializer)

* XmlDocument

* XmlIgnore

* Serializable

* XmlNode

* BinaryFormatter

* SoapFormatter

* Inflaterinputstream

* DataContractSerializer (Install-package System.Runtime.Serialization.Xml)

* DataContractJsonSerializer (Install-package System.Runtime.Serialization.Json)

2. Partial reflection needs to be reformed, you need to reference the following:

* System.Reflection

* System.Reflection.Primitives

* System.Reflection.Extensions

* System.Reflection.TypeExtensions

* If You need IL generation then add System.Reflection.Emit andSystem.Reflection.Emit.ILGeneration

* For example, type.getproperties () should be changed to Type.gettypeinfo (). GetProperties ()

* assembly.getexecutingassembly () https://forums.asp.net/t/2001385.aspx not supported

3. Tasks and threading and async/await is available, but you'll have the reference the following:

* System.Threading.Thread

* System.Threading.Tasks

4. Sockets is available but your need to reference the following:

* System.Net.Sockets.

* System.Net.Security if you want SslStream.

* Also, Socket. Close () is the now socket. Dispose ()

5. Remoting,it ' s used for cross-appdomain communication, which is no longer supported. Also, Remoting requires runtime support, which are expensive to maintain.

6. Async is supported (see above point) but the older iasyncresult-based Async isn't supported. You'll have the disable those sections using #if tags or upgrade to async/await.

7. Serialization by converting data to and from Binary are unsupported, but XML, and JSON serialization are. (see SYSTEM.RUNTIME.SERIALIZATION.XML and System.Runtime.Serialization.Json)

8. Crypto is available but many classes be renamed and refactored, for eg. New SHA1CryptoServiceProvider () is now SHA256. Create ().

9. StackTrace is available and need the extra System.Diagnostics.StackTrace, so if it's not essential your may want to r Emove from your code rather than add an additional dependency

The XAML is unsupported and if you are targeting UWP, you'll have a to use the Windows RT XAML APIs.

11. Partial objects are not supported:

* ArrayList

* Hashtable

* HybridDictionary

* BindingList

* Thread (Install-package System.Threading.Thread)

* Process (Install-package System.Diagnostics.Process)

* HttpContext

* AppDomain

* Dataset/datatable/dbnull. DataTable and DataSet is not available in the System.Data namespace but other features like the provider model and SQL CLI ENT is available.

12. The registry cannot be accessed

* RegistryKey

13. The related configuration object is not supported:

* ConfigurationManager

* WebConfigurationManager

* ConfigurationSection

14. Drawing is not supported

* System.Drawing

* System.Drawing.Size

15. Cannot use related Web objects

*system.web.httputility.htmldecode

16. Many streams do not have a close () method and are replaced directly with the Dispose ()

DateTime.Now.ToShortDateString () replaced by DateTime.Now.ToString ("Yyyy-mm-dd")

18. Partial Attribute not supported

* DescriptionAttribute

Webresponse/webrequest object has changed

* Not supported: httpwebresponse.contentencoding, unable to identify whether the response was added gzip, or it may be automatically recognized

* Not supported: Httpwebrequest.referer/. UserAgent Unable to set request browser and source address

Some Key Missing components: (source)

* System.appdomain-app Domains

* System.drawing.image-graphics, Bitmap Images

* System.directoryservices-ldap, Active Directory

* System.transactions-ambient transactions, distributed transactions

* SYSTEM.XML.XSL-XSLT

* System.xml.schema-xsd

* System.net.mail-sending Email

* System.runtime.remoting-remoting, RPC

* System.runtime.serialization.xml-binary Serialization

* System.io.ports-serial Port

* System.workflow-windows Workflow Foundation

. NET Core 2.0 learning Note (iv): Migrating. NET Framework Engineering to. NET Core

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.