Skip to content

Commit 753ed6b

Browse files
Migration docs revamp. (#24630)
* Update with the minimal changes needed to align existing content to the new TOC. * Adding the new page 'tooling-requirements.md' and adding initial content to resolve #24568 * Created additional pages needed for Phase 1 modifying the TOC as needed. * Created additional pages needed for Phase 1 modifying the TOC as needed. * Update docs/core/porting/premigration-needed-changes.md * Update docs/core/porting/premigration-needed-changes.md * Add breaking change page. * Add breaking change page. * Update tooling requirements page based on feedback. * Update breaking changes page. * Update breaking changes page. * Rename and move thepage about sdk, msbuild and vs versioning. * Rename and move thepage about sdk, msbuild and vs versioning. * Latest round of feedback updates. * Latest round of feedback updates. * Update docs/core/porting/breaking-changes.md Co-authored-by: Andy (Steve) De George <[email protected]> * Update breaking-changes.md * Update versioning....md * Upgrade porting-approaches.md * Upgrade premigration-needed-changes.md * Upgrade project-structure.md * Upgrade unsupported-apis.md * TOC naming changes * Update docs/core/porting/project-structure.md Co-authored-by: Andy (Steve) De George <[email protected]> * Update docs/core/porting/project-structure.md Co-authored-by: Andy (Steve) De George <[email protected]> * Update porting-approaches.md * Update premigration-needed-changes.md Co-authored-by: Andy (Steve) De George <[email protected]> Co-authored-by: Andy De George (adegeo) <[email protected]>
1 parent 970adc3 commit 753ed6b

File tree

8 files changed

+348
-66
lines changed

8 files changed

+348
-66
lines changed

docs/core/porting/breaking-changes.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Breaking changes can affect porting your app
3+
description: Breaking changes can occur when porting your code from .NET framework to .NET and between versions of .NET. This article describes categories of breaking changes, ways a change can affect compatibility and how to find breaking changes.
4+
author: StephenBonikowsky
5+
ms.author: stebon
6+
ms.date: 06/14/2021
7+
---
8+
# Breaking changes may occur when porting code
9+
10+
Changes that affect compatibility, otherwise known as breaking changes, will occur between versions of .NET. Changes are impactful when porting from .NET Framework to .NET because of certain technologies not being available. Also, you can come across breaking changes simply because .NET is a cross-platform technology and .NET Framework isn't.
11+
12+
Microsoft strives to maintain a high level of compatibility between .NET versions, so while breaking changes do occur, they're carefully considered.
13+
14+
Before upgrading major versions, check the breaking changes documentation for changes that might affect you.
15+
16+
## Categories of breaking changes
17+
18+
There are several types of breaking changes...
19+
20+
- modifications to the public contract
21+
- behavioral changes
22+
- Platform support
23+
- Internal implementation changes
24+
- Code changes
25+
26+
For more information about what is allowed or disallowed, see [Changes that affect compatibility](../compatibility/index.md)
27+
28+
## Types of compatibility
29+
30+
Compatibility refers to the ability to compile or run code on a .NET implementation other than the one with which the code was originally developed.
31+
32+
There are six different ways a change can affect compatibility...
33+
34+
- Behavioral changes
35+
- Binary compatibility
36+
- Source compatibility
37+
- Design-time compatibility
38+
- Backwards compatibility
39+
- Forward compatibility
40+
41+
For more information, see [How code changes can affect compatibility](../compatibility/categories.md)
42+
43+
## Find breaking changes
44+
45+
Changes that affect compatibility are documented and should be reviewed before porting from .NET Framework to .NET or when upgrading to a newer version of .NET.
46+
47+
For more information, see [Breaking changes reference overview](../compatibility/breaking-changes.md)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: Porting approaches
3+
description: Create a porting plan that best reflects your project and context.
4+
author: StephenBonikowsky
5+
ms.author: stebon
6+
ms.date: 06/10/2021
7+
---
8+
# Create a porting plan
9+
10+
Before you jump straight into the code, take the time to go through the recommended pre-migration steps. This article gives you insight into the kinds of issues you may come across, and helps you decide on an approach that makes the most sense.
11+
12+
## Port your code
13+
14+
Make sure that you follow the [prerequisites to porting code](premigration-needed-changes.md) before you continue any further. Be ready to decide on the best approach for you and begin porting code.
15+
16+
### Deal primarily with the compiler
17+
18+
This approach works well for small projects or projects that don't use many .NET Framework APIs. The approach is simple:
19+
20+
01. Optionally, run **ApiPort** on your project. If you run **ApiPort**, gain knowledge from the report on issues you'll need to address.
21+
01. Copy all of your code over into a new .NET project.
22+
01. While referring to the portability report (if generated), solve compiler errors until the project fully compiles.
23+
24+
Although it's unstructured, this code-focused approach often resolves issues quickly. A project that contains only data models might be an ideal candidate for this approach.
25+
26+
### Stay on the .NET Framework until portability issues are resolved
27+
28+
This approach might be the best if you prefer to have code that compiles during the entire process. The approach is as follows:
29+
30+
01. Run **ApiPort** on a project.
31+
01. Address issues by using different APIs that are portable.
32+
01. Take note of any areas where you're prevented from using a direct alternative.
33+
01. Repeat the prior steps for all projects you're porting until you're confident each is ready to be copied over into a new .NET project.
34+
01. Copy the code into a new .NET project.
35+
01. Work out any issues where you noted that a direct alternative doesn't exist.
36+
37+
This careful approach is more structured than simply working out compiler errors, but it's still relatively code-focused and has the benefit of always having code that compiles. The way you resolve certain issues that couldn't be addressed by just using another API varies greatly. You may find that you need to develop a more comprehensive plan for certain projects, which is covered in the next approach.
38+
39+
### Develop a comprehensive plan of attack
40+
41+
This approach might be best for larger and more complex projects, where restructuring code or completely rewriting certain areas of code might be necessary to support .NET. The approach is as follows:
42+
43+
01. Run **ApiPort** on a project.
44+
01. Understand where each non-portable type is used and how that affects overall portability.
45+
46+
- Understand the nature of those types. Are they small in number but used frequently? Are they large in number but used infrequently? Is their use concentrated, or is it spread throughout your code?
47+
- Is it easy to isolate code that isn't portable so that you can deal with it more effectively?
48+
- Do you need to refactor your code?
49+
- For those types that aren't portable, are there alternative APIs that accomplish the same task? For example, if you're using the <xref:System.Net.WebClient> class, use the <xref:System.Net.Http.HttpClient> class instead.
50+
- Are there different portable APIs available to accomplish a task, even if it's not a drop-in replacement? For example, if you're using <xref:System.Xml.Schema.XmlSchema> to parse XML but don't require XML schema discovery, you could use <xref:System.Xml.Linq> APIs and implement parsing yourself instead of relying on an API.
51+
52+
01. If you have assemblies that are difficult to port, is it worth leaving them on .NET Framework for now? Here are some things to consider:
53+
54+
- You may have some functionality in your library that's incompatible with .NET because it relies too heavily on .NET Framework or Windows-specific functionality. Is it worth leaving that functionality behind for now and releasing a temporary .NET version of your library with fewer features until resources are available to port the features?
55+
- Would a refactor help?
56+
57+
01. Is it reasonable to write your own implementation of an unavailable .NET Framework API?
58+
59+
You could consider copying, modifying, and using code from the [.NET Framework reference source](https://github.com/Microsoft/referencesource). The reference source code is licensed under the [MIT License](https://github.com/Microsoft/referencesource/blob/master/LICENSE.txt), so you have significant freedom to use the source as a basis for your own code. Just be sure to properly attribute Microsoft in your code.
60+
61+
01. Repeat this process as needed for different projects.
62+
63+
The analysis phase could take some time depending on the size of your codebase. Spending time in this phase to thoroughly understand the scope of changes needed and to develop a plan usually saves you time in the end, particularly if you have a complex codebase.
64+
65+
Your plan could involve making significant changes to your codebase while still targeting .NET Framework 4.7.2. This is a more structured version of the previous approach. How you go about executing your plan is dependent on your codebase.
66+
67+
### Mixed approach
68+
69+
It's likely that you'll mix the above approaches on a per-project basis. Do what makes the most sense to you and for your codebase.
70+
71+
## Port your tests
72+
73+
The best way to make sure everything works when you've ported your code is to test your code as you port it to .NET. To do this, you'll need to use a testing framework that builds and runs tests for .NET. Currently, you have three options:
74+
75+
- [xUnit](https://xunit.net/)
76+
- [Getting Started](https://xunit.net/docs/getting-started/netcore/cmdline)
77+
- [Tool to convert an MSTest project to xUnit](https://github.com/dotnet/codeformatter/tree/main/src/XUnitConverter)
78+
- [NUnit](https://nunit.org/)
79+
- [Getting Started](https://github.com/nunit/docs/wiki/Installation)
80+
- [Blog post about migrating from MSTest to NUnit](https://www.florian-rappl.de/News/Page/275/convert-mstest-to-nunit)
81+
- [MSTest](/visualstudio/test/unit-test-basics)
82+
83+
## Recommended approach
84+
85+
Ultimately, the porting effort depends heavily on how your .NET Framework code is structured. A good way to port your code is to begin with the *base* of your library, which is the foundational components of your code. This might be data models or some other foundational classes and methods that everything else uses directly or indirectly.
86+
87+
01. Port the test project that tests the layer of your library that you're currently porting.
88+
01. Copy over the base of your library into a new .NET project and select the version of .NET Standard you wish to support.
89+
01. Make any changes needed to get the code to compile. Much of this may require adding NuGet package dependencies to your *csproj* file.
90+
01. Run the tests and make any needed adjustments.
91+
01. Pick the next layer of code to port over and repeat the prior steps.
92+
93+
If you start with the base of your library and move outward from the base and test each layer as needed, porting is a systematic process where problems are isolated to one layer of code at a time.
94+
95+
## Next steps
96+
97+
- [Overview of the .NET Upgrade Assistant](upgrade-assistant-overview.md)
98+
- [Organize your project to support both .NET Framework and .NET Core](project-structure.md)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Prerequisites to port from .NET Framework
3+
description: Before porting your code from .NET Framework to .NET, you must use the correct developer environment and update your project files as required.
4+
author: StephenBonikowsky
5+
ms.author: stebon
6+
ms.date: 06/10/2021
7+
---
8+
# Prerequisites to porting code
9+
10+
Make the needed changes to build and run a .NET application before beginning the work to port your code. These changes can be done while still building and running a .NET Framework application.
11+
12+
## Upgrade to required tooling
13+
14+
Upgrade to a version of MSBuild/Visual Studio that supports the version of .NET you will be targeting. See [Versioning relationship between the .NET SDK, MSBuild and VS](versioning-sdk-msbuild-vs.md) for more info.
15+
16+
## Update .NET Framework target version
17+
18+
We recommended that you target your .NET Framework app to version 4.7.2 or higher. This ensures the availability of the latest API alternatives for cases where .NET Standard doesn't support existing APIs.
19+
20+
For each of the projects you wish to port, do the following in Visual Studio:
21+
22+
01. Right-click on the project and select **Properties**.
23+
01. In the **Target Framework** dropdown, select **.NET Framework 4.7.2**.
24+
01. Recompile the project.
25+
26+
Because your projects now target .NET Framework 4.7.2, use that version of the .NET Framework as your base for porting code.
27+
28+
## Change to PackageReference format
29+
30+
Convert all references to the [PackageReference](/nuget/consume-packages/package-references-in-project-files) format.
31+
32+
## Convert to SDK style project format
33+
34+
Convert your projects to the [SDK-style format](../project-sdk/overview.md).
35+
36+
## Update dependencies
37+
38+
Update dependencies to their latest version available, and to .NET Standard version where possible.
39+
40+
## Next steps
41+
42+
- [Create a porting plan](porting-approaches.md)
Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,61 @@
11
---
2-
title: Organize projects for .NET Framework and .NET Core
3-
description: Help for project owners who want to compile their solution against .NET Framework and .NET Core side-by-side.
2+
title: Organize projects for .NET Framework and .NET
3+
description: Help for project owners who want to compile their solution against .NET Framework and .NET side by side.
44
author: conniey
5-
ms.date: 12/07/2018
5+
ms.date: 07/02/2021
66
---
7-
# Organize your project to support both .NET Framework and .NET Core
7+
# Organize your project to support both .NET Framework and .NET
88

9-
You can create a solution that compiles for both .NET Framework and .NET Core side-by-side. This article covers several project-organization options to help you achieve this goal. Here are some typical scenarios to consider when you're deciding how to set up your project layout with .NET Core. The list may not cover everything you want; prioritize based on your project's needs.
9+
You can create a solution that compiles for both .NET Framework and .NET side by side. This article covers several project-organization options to help you achieve this goal. Here are some typical scenarios to consider when you're deciding how to set up your project layout with .NET. The list may not cover everything you want.
1010

11-
- [**Combine existing projects and .NET Core projects into single projects**](#replace-existing-projects-with-a-multi-targeted-net-core-project)
11+
- [Combine existing projects and .NET projects into a single project](#replace-existing-projects-with-a-multi-targeted-net-project)
12+
13+
**Benefits**:
1214

13-
*What this is good for:*
1415
- Simplifies your build process by compiling a single project rather than multiple projects that each target a different .NET Framework version or platform.
15-
- Simplifies source file management for multi-targeted projects because you must manage a single project file. When adding or removing source files, the alternatives require you to manually sync these with your other projects.
16+
- Simplifies source file management for multi-targeted projects because you must manage a single project file. When adding or removing source files, the alternatives require you to manually sync these files with your other projects.
1617
- Easily generate a NuGet package for consumption.
17-
- Allows you to write code for a specific .NET Framework version in your libraries through the use of compiler directives.
18+
- Allows you to write code for a specific .NET Framework version by using compiler directives.
1819

19-
*Unsupported scenarios:*
20-
- Requires developers to use Visual Studio 2017 or a later version to open existing projects. To support older versions of Visual Studio, [keeping your project files in different folders](#support-vs) is a better option.
20+
**Drawback**:
2121

22-
- <a name="support-vs"></a>[**Keep existing projects and new .NET Core projects separate**](#keep-existing-projects-and-create-a-net-core-project)
22+
- Requires developers to use Visual Studio 2019 or a later version to open existing projects. To support older versions of Visual Studio, [keeping your project files in different folders](#support-vs) is a better option.
2323

24-
*What this is good for:*
25-
- Supports development on existing projects for developers and contributors who may not have Visual Studio 2017 or a later version.
26-
- Decreases the possibility of creating new bugs in existing projects because no code churn is required in those projects.
24+
- <a name="support-vs"></a>[Keep all projects separate](#keep-existing-projects-and-create-a-net-project)
2725

28-
## Example
26+
**Benefits**:
2927

30-
Consider the repository below:
28+
- Supports development on existing projects for developers and contributors who may not have Visual Studio 2019 or a later version.
29+
- Lowers the possibility of creating new bugs in existing projects because no code churn is required in those projects.
3130

32-
![Existing project](./media/project-structure/existing-project-structure.png)
31+
Consider [this example GitHub repository](https://github.com/dotnet/samples/tree/main/framework/libraries/migrate-library/). The figure below shows how this repository is laid out:
3332

34-
[**Source Code**](https://github.com/dotnet/samples/tree/main/framework/libraries/migrate-library/)
33+
:::image type="content" source="media/project-structure/existing-project-structure.png" alt-text="Existing project structure diagram":::
3534

36-
The following describes several ways to add support for .NET Core for this repository depending on the constraints and complexity of the existing projects.
35+
The following sections describe several ways to add support for .NET based on the example repository.
3736

38-
## Replace existing projects with a multi-targeted .NET Core project
37+
## Replace existing projects with a multi-targeted .NET project
3938

40-
Reorganize the repository so that any existing *\*.csproj* files are removed and a single *\*.csproj* file is created that targets multiple frameworks. This is a great option, because a single project is able to compile for different frameworks. It also has the power to handle different compilation options and dependencies per targeted framework.
39+
Reorganize the repository so that any existing *\*.csproj* files are removed and a single *\*.csproj* file is created that targets multiple frameworks. This is a great option, because a single project can compile for different frameworks. It also has the power to handle different compilation options and dependencies per targeted framework.
4140

42-
![Create a csproj that targets multiple frameworks](./media/project-structure/multi-targeted-project.png)
41+
:::image type="content" source="media/project-structure/multi-targeted-project.png" alt-text="project that targets multiple frameworks diagram":::
4342

44-
[**Source Code**](https://github.com/dotnet/samples/tree/main/framework/libraries/migrate-library-csproj/)
43+
For example code, see [GitHub](https://github.com/dotnet/samples/tree/main/framework/libraries/migrate-library-csproj/).
4544

4645
Changes to note are:
4746

48-
- Replacement of *packages.config* and *\*.csproj* with a new [.NET Core *\*.csproj*](https://github.com/dotnet/samples/tree/main/framework/libraries/migrate-library-csproj/src/Car/Car.csproj). NuGet packages are specified with `<PackageReference> ItemGroup`.
47+
- Replacement of *packages.config* and *\*.csproj* with a new [.NET *\*.csproj*](https://github.com/dotnet/samples/tree/main/framework/libraries/migrate-library-csproj/src/Car/Car.csproj). NuGet packages are specified with `<PackageReference> ItemGroup`.
4948

50-
## Keep existing projects and create a .NET Core project
49+
## Keep existing projects and create a .NET project
5150

52-
If there are existing projects that target older frameworks, you may want to leave these projects untouched and use a .NET Core project to target future frameworks.
51+
If there are existing projects that target older frameworks, you may want to leave these projects untouched and use a .NET project to target future frameworks.
5352

54-
![.NET Core project with existing project in different folder](./media/project-structure/separate-projects-same-source.png)
53+
:::image type="content" source="media/project-structure/separate-projects-same-source.png" alt-text=".NET project with existing projects in a different folder diagram":::
5554

56-
[**Source Code**](https://github.com/dotnet/samples/tree/main/framework/libraries/migrate-library-csproj-keep-existing/)
55+
For example code, see [GitHub](https://github.com/dotnet/samples/tree/main/framework/libraries/migrate-library-csproj-keep-existing/).
5756

58-
The .NET Core and existing projects are kept in separate folders. Keeping projects in separate folders avoids forcing you to have Visual Studio 2017 or later versions. You can create a separate solution that only opens the old projects.
57+
The .NET and existing projects are kept in separate folders. Keeping projects in separate folders avoids forcing you to have Visual Studio 2019 or later versions. You can create a separate solution that only opens the old projects.
5958

6059
## See also
6160

62-
- [.NET Core porting documentation](index.md)
61+
- [.NET porting documentation](index.md)

0 commit comments

Comments
 (0)