You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update porting overview and dependencies section (#14621)
* Update porting overview and dependencies section
* Apply suggestions from code review
Co-Authored-By: Maira Wenzel <mairaw@microsoft.com>
* Changes based on feedback
* More rewording in overview to make some items clearer
* Update suggested tool to convert
* Apply suggestions from code review
Co-Authored-By: Maira Wenzel <mairaw@microsoft.com>
* Updates based on feedback
description: Understand the porting process and discover tools you may find helpful when porting a .NET Framework project to .NET Core.
4
4
author: cartermp
5
-
ms.date: 09/13/2019
5
+
ms.date: 10/22/2019
6
6
ms.custom: seodec18
7
7
---
8
-
# Port your code from .NET Framework to .NET Core
8
+
# Overview of the porting process from .NET Framework to .NET Core
9
9
10
-
If you've got code that runs on the .NET Framework, you may be interested in running your code on .NET Core, too. Here's an overview of the porting process and a list of the tools you may find helpful when porting your code to .NET Core.
10
+
You might have code that currently runs on the .NET Framework that you're interested in porting to .NET Core. This article provides:
11
11
12
-
## Overview of the porting process
13
-
14
-
This is the process we recommend you take when porting your project to .NET Core. Each step of the process is covered in more detail in further articles.
12
+
* An overview of the porting process.
13
+
* A list of the tools you may find helpful when you're porting your code to .NET Core.
15
14
16
-
1. Identify and account for your third-party dependencies.
15
+
## Overview of the porting process
17
16
18
-
This step involves understanding what your third-party dependencies are, how you depend on them, how to check if they also run on .NET Core, and steps you can take if they don't. It also covers how you can migrate your dependencies over to the [PackageReference](/nuget/consume-packages/package-references-in-project-files) format that is used in .NET Core.
17
+
We recommend you to use the following process when porting your project to .NET Core:
19
18
20
-
2. Retarget all projects you wish to port to target the .NET Framework 4.7.2 or higher.
19
+
1. Retarget all projects you wish to port to target the .NET Framework 4.7.2 or higher.
21
20
22
21
This step ensures that you can use API alternatives for .NET Framework-specific targets when .NET Core doesn't support a particular API.
23
22
24
-
3. Use the [.NET Portability Analyzer](../../standard/analyzers/portability-analyzer.md) to analyze your assemblies and develop a plan to port based on its results.
23
+
2. Use the [.NET Portability Analyzer](../../standard/analyzers/portability-analyzer.md) to analyze your assemblies and see if they're portable to .NET Core.
24
+
25
+
The API Portability Analyzer tool analyzes your compiled assemblies and generates a report. This report shows a high-level portability summary and a breakdown of each API you're using that isn't available on NET Core.
25
26
26
-
The API Portability Analyzer tool analyzes your compiled assemblies and generates a report that shows a high-level portability summary and a breakdown of each API you're using that isn't available on targeted .NET Core platform public surface. You can use this report alongside an analysis of your codebase to develop a plan for how you'll port your code over.
27
+
3. Install the [.NET API analyzer](../../standard/analyzers/api-analyzer.md) into your projects to identify APIs throwing <xref:System.PlatformNotSupportedException> on some platforms and some other potential compatibility issues.
27
28
28
-
4. Once you have your project file converted to your targeted .NET Core version, you can use Roslyn based [.NET API analyzer](../../standard/analyzers/api-analyzer.md) to identify APIs throwing <xref:System.PlatformNotSupportedException>on some platforms and some other potential compatibility issues.
29
+
This tool is similar to the portability analyzer, but instead of analyzing if things can build on .NET Core, it will analyze if you're using an API in a way that will throw the <xref:System.PlatformNotSupportedException>at runtime. Although this isn't common if you're moving from .NET Framework 4.7.2 or higher, it's good to check.
29
30
30
-
5. Port your tests code.
31
+
4. Convert all of your `packages.config` dependencies to the [PackageReference](/nuget/consume-packages/package-references-in-project-files) format with the [conversion tool in Visual Studio](/nuget/consume-packages/migrate-packages-config-to-package-reference).
31
32
32
-
Because porting to .NET Core is such a significant change to your codebase, it's highly recommended to get your tests ported, so that you can run tests as you port your code over. MSTest, xUnit, and NUnit all support .NET Core.
33
+
This step involves converting your dependencies from the legacy `packages.config` format. `packages.config` doesn't work on .NET Core, so this conversion is required if you have package dependencies.
33
34
34
-
6. Execute your plan for porting!
35
+
5. Create new projects for .NET Core and copy over source files, or attempt to convert your existing project file with a tool.
35
36
36
-
The following list shows tools you might find helpful to use during the porting process:
37
+
.NET Core uses a simplified (and different) [project file format](../tools/csproj.md) than .NET Framework. You'll need to convert your project files into this format to continue.
37
38
38
-
- .NET Portability Analyzer - [command-line tool](https://github.com/Microsoft/dotnet-apiport/releases) or [Visual Studio Extension](https://marketplace.visualstudio.com/items?itemName=ConnieYau.NETPortabilityAnalyzer), a tool that can generate a report of how portable your code is between .NET Framework and your target .NET Core platform. The report contains an assembly-by-assembly breakdown of the Type and APIs missing on the target .NET Core platform. For more information, see [.NET Portability Analyzer](../../standard/analyzers/portability-analyzer.md). It is recommended to run the .NET Portability Analyzer tool before you start porting, as it will help you identify any gaps in missing APIs in specific targeted .NET platform public surface.
39
-
- .NET API Analyzer - A Roslyn analyzer that discovers .NET Standard API that throws <xref:System.PlatformNotSupportedException> on some platforms, detects calls to deprecated APIs, and discovers some other potential compatibility risks for C# APIs on different platforms. For more information, see [.NET API analyzer](../../standard/analyzers/api-analyzer.md). This analyzer is helpful after you already created your .NET Core project to identify runtime behavior differences on different platforms.
40
-
- Reverse Package Search - A [useful web service](https://packagesearch.azurewebsites.net) that allows you to search for a type and find packages containing that type.
39
+
6. Port your test code.
41
40
42
-
Additionally, you can attempt to port smaller solutions or individual projects to the .NET Core project file format with the [CsprojToVs2017](https://github.com/hvanbakel/CsprojToVs2017) tool.
41
+
Because porting to .NET Core is such a significant change to your codebase, it's highly recommended to get your tests ported, so that you can run tests as you port your code over. MSTest, xUnit, and NUnit all work on .NET Core.
43
42
44
-
> [!WARNING]
45
-
> CsprojToVs2017 is a third-party tool. There is no guarantee that it will work for all of your projects, and it may cause subtle changes in behavior that you depend on. CsprojToVs2017 should be used as a _starting point_ that automates the basic things that can be automated. It is not a guaranteed solution to migrating project file formats.
43
+
Additionally, you can attempt to port smaller solutions or individual projects to the .NET Core project file format with the [dotnet try-convert](https://github.com/dotnet/try-convert) tool in one operation. `dotnet try-convert` is not guaranteedto work for all your projects, and it may cause subtle changes in behavior that you may find that you depended on. It should be used as a _starting point_ that automates the basic things that can be automated. It isn't a guaranteed solution to migrating a project.
Copy file name to clipboardExpand all lines: docs/core/porting/third-party-deps.md
+23-43Lines changed: 23 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,22 +2,34 @@
2
2
title: Analyze dependencies to port code to .NET Core
3
3
description: Learn how to analyze external dependencies in order to port your project from .NET Framework to .NET Core.
4
4
author: cartermp
5
-
ms.date: 12/07/2018
5
+
ms.date: 10/22/2019
6
6
ms.custom: seodec18
7
7
---
8
8
# Analyze your dependencies to port code to .NET Core
9
9
10
-
To port your code to .NET Core or .NET Standard, you must understand your dependencies. External dependencies are the [NuGet packages](#analyze-referenced-nuget-packages-in-your-projects) or [DLLs](#analyze-dependencies-that-arent-nuget-packages) you reference in your project, but that you don't build. Evaluate each dependency and develop a contingency plan for the ones that aren't compatible with .NET Core. Here's how to determine if a dependency is compatible with .NET Core.
10
+
To port your code to .NET Core or .NET Standard, you must understand your dependencies. External dependencies are the NuGet packages or `.dll`s you reference in your project, but that you don't build yourself.
11
11
12
-
## Analyze referenced NuGet packages in your projects
12
+
## Migrate your NuGet packages to `PackageReference`
13
13
14
-
If you reference NuGet packages in your project, you need to verify if they're compatible with .NET Core.
15
-
There are two ways to accomplish that:
14
+
.NET Core uses [PackageReference](/nuget/consume-packages/package-references-in-project-files) to specify package dependencies. If you're using [packages.config](/nuget/reference/packages-config) to specify your packages in your project, you need to convert it to the `PackageReference` format because `packages.config` isn't supported in .NET Core.
16
15
17
-
-[Using the NuGet Package Explorer app](#analyze-nuget-packages-using-nuget-package-explorer)
18
-
-[Using the nuget.org site](#analyze-nuget-packages-using-nugetorg)
16
+
To learn how to migrate, see the [Migrate from packages.config to PackageReference](/nuget/reference/migrate-packages-config-to-package-reference) article.
19
17
20
-
After analyzing the packages, if they're not compatible with .NET Core and only target .NET Framework, you can check if the [.NET Framework compatibility mode](#net-framework-compatibility-mode) can help with your porting process.
18
+
## Upgrade your NuGet packages
19
+
20
+
After your migrating your project to the `PackageReference` format, you need to verify if your packages are compatible with .NET Core.
21
+
22
+
First, upgrade your packages to the latest version that you can. This can be done with the NuGet Package Manager UI in Visual Studio. It's likely that newer versions of your package dependencies are already compatible with .NET Core.
23
+
24
+
## Analyze your package dependencies
25
+
26
+
If you haven't already verified that your converted and upgraded package dependencies work on .NET Core, there are a few ways that you can achieve that:
27
+
28
+
### Analyze NuGet packages using nuget.org
29
+
30
+
You can see the Target Framework Monikers (TFMs) that each package supports on [nuget.org](https://www.nuget.org/) under the **Dependencies** section of the package page.
31
+
32
+
Although using the site is an easier method to verify the compatibility, **Dependencies** information isn't available on the site for all packages.
21
33
22
34
### Analyze NuGet packages using NuGet Package Explorer
23
35
@@ -31,43 +43,17 @@ The easiest way to inspect NuGet Package folders is to use the [NuGet Package Ex
31
43
4. Select the package name from the search results and click **open**.
32
44
5. Expand the *lib* folder on the right-hand side and look at folder names.
33
45
34
-
Look for a folder with any of the following names:
35
-
36
-
```
37
-
netstandard1.0
38
-
netstandard1.1
39
-
netstandard1.2
40
-
netstandard1.3
41
-
netstandard1.4
42
-
netstandard1.5
43
-
netstandard1.6
44
-
netstandard2.0
45
-
netcoreapp1.0
46
-
netcoreapp1.1
47
-
netcoreapp2.0
48
-
netcoreapp2.1
49
-
netcoreapp2.2
50
-
portable-net45-win8
51
-
portable-win8-wpa8
52
-
portable-net451-win81
53
-
portable-net45-win8-wpa8-wpa81
54
-
```
46
+
Look for a folder with names using one the following patterns: `netstandardX.Y` or `netcoreappX.Y`.
55
47
56
48
These values are the [Target Framework Monikers (TFMs)](../../standard/frameworks.md) that map to versions of the [.NET Standard](../../standard/net-standard.md), .NET Core, and traditional Portable Class Library (PCL) profiles that are compatible with .NET Core.
57
49
58
50
> [!IMPORTANT]
59
51
> When looking at the TFMs that a package supports, note that `netcoreapp*`, while compatible, is for .NET Core projects only and not for .NET Standard projects.
60
52
> A library that only targets `netcoreapp*` and not `netstandard*` can only be consumed by other .NET Core apps.
61
53
62
-
### Analyze NuGet packages using nuget.org
63
-
64
-
Alternatively, you can see the TFMs that each package supports on [nuget.org](https://www.nuget.org/) under the **Dependencies** section of the package page.
65
-
66
-
Although using the site is an easier method to verify the compatibility, **Dependencies** information is not available on the site for all packages.
54
+
## .NET Framework compatibility mode
67
55
68
-
### .NET Framework compatibility mode
69
-
70
-
After analyzing the NuGet packages, you might find that they only target the .NET Framework, as most NuGet packages do.
56
+
After analyzing the NuGet packages, you might find that they only target the .NET Framework.
71
57
72
58
Starting with .NET Standard 2.0, the .NET Framework compatibility mode was introduced. This compatibility mode allows .NET Standard and .NET Core projects to reference .NET Framework libraries. Referencing .NET Framework libraries doesn't work for all projects, such as if the library uses Windows Presentation Foundation (WPF) APIs, but it does unblock many porting scenarios.
73
59
@@ -87,12 +73,6 @@ To suppress the warning by editing the project file, find the `PackageReference`
87
73
88
74
For more information on how to suppress compiler warnings in Visual Studio, see [Suppressing warnings for NuGet packages](/visualstudio/ide/how-to-suppress-compiler-warnings#suppress-warnings-for-nuget-packages).
89
75
90
-
## Port your packages to `PackageReference`
91
-
92
-
.NET Core uses [PackageReference](/nuget/consume-packages/package-references-in-project-files) to specify package dependencies. If you are using [packages.config](/nuget/reference/packages-config) to specify your packages, you will need to convert over to `PackageReference`.
93
-
94
-
You can learn more at [Migrate from packages.config to PackageReference](/nuget/reference/migrate-packages-config-to-package-reference).
95
-
96
76
## What to do when your NuGet package dependency doesn't run on .NET Core
97
77
98
78
There are a few things you can do if a NuGet package you depend on doesn't run on .NET Core:
0 commit comments