Doesthat mean that my .Net framework apps can be recompiled in .Net 6, as long as I specify the net-windows target and the csproject upgrade and compilation is successful, the program will just work? I just intend them to run on Windows, now and always.
My apps also consume a lot of .Net framework 2.0/3.5/4.6 dlls ( mostly they are involved with OpenGL and other graphic things), which I can only assume to have no general port to .Net 5 or .Net 6, and which the source code is no longer available even to me ( they are from close-source third party providers).
Speaking from experience, in many cases it is easier to create a clean project in the new framework, copy all the existing files from the old project then re-add NuGet and project references. I have done this successfully for Console Apps, Test Projects and even a WinForms app 15-20 project dependencies to .NET 4.8 projects and it has worked out of the box - albeit with a compiler warning about the .NET 4.8 dependencies.
However I have also come across at least one missing / changed API between 4.8 and 5.0 - BeginInvoke. A blog post here describes it in more detail. Sometimes there are also issues with NuGet versions.
The closest thing to a definitive list online is the MS Doc "Changes that affect compatibility" and in particular the Breaking changes for migration from .NET Framework to .NET Core section. I'm not sure the is a better "answer from a reputable source" out there.
As for your .NET 2.0 / 3.5 / 4.6 dlls I don't think there is anyway of knowing without trying. There are simply too many unknowns, especially as they are 3rd party dlls. If I had to guess it would be that at least one won't work, whether you can find an updated version or how much work an alternative library will be to incorporate will be impossible to tell
As for net5.0-windows, it's basically a fudge. While the goal of everything .NET 5.0 onwards was unification and cross-platform everything, they couldn't get all the work done in time. I read a blob post about it, which I can't find right now, but basically WinForms in particular is very closely tied to some underlying Windows only APIs. Maybe .NET 7.0?
When you target a framework in an app or library, you're specifying the set of APIs that you'd like to make available to the app or library. You specify the target framework in your project file using a target framework moniker (TFM).
An app or library can target a version of .NET Standard. .NET Standard versions represent standardized sets of APIs across all .NET implementations. For example, a library can target .NET Standard 1.6 and gain access to APIs that function across .NET Core and .NET Framework using the same codebase.
An app or library can also target a specific .NET implementation to gain access to implementation-specific APIs. For example, an app that targets Xamarin.iOS (for example, Xamarin.iOS10) has access to Xamarin-provided iOS API wrappers for iOS 10, or an app that targets Universal Windows Platform (UWP, uap10.0) has access to APIs that compile for devices that run Windows 10.
The following table defines the most common target frameworks, how they're referenced, and which version of .NET Standard they implement. These target framework versions are the latest stable versions. Prerelease versions aren't shown. A target framework moniker (TFM) is a standardized token format for specifying the target framework of a .NET app or library.
A target framework is typically referenced by a TFM. The following table shows the target frameworks supported by the .NET SDK and the NuGet client. Equivalents are shown within brackets. For example, win81 is an equivalent TFM to netcore451.
The net5.0, net6.0, net7.0, and net8.0 TFMs include technologies that work across different platforms. Specifying an OS-specific TFM makes APIs that are specific to an operating system available to your app, for example, Windows Forms or iOS bindings. OS-specific TFMs also inherit every API available to their base TFM, for example, the net6.0 TFM.
.NET 5 introduced the net5.0-windows OS-specific TFM, which includes Windows-specific bindings for WinForms, WPF, and UWP APIs. .NET 6 and later versions have additional OS-specific TFMs, for example, net6.0-ios.
To make your app portable across different platforms but still have access to OS-specific APIs, you can target multiple OS-specific TFMs and add platform guards around OS-specific API calls using #if preprocessor directives. For a list of the available symbols, see Preprocessor symbols.
Cross-platform application models (Xamarin Forms,
ASP.NET Core) and bridge packs (Xamarin Essentials) should at least target the base TFM, for example, net8.0, but might also target additional platform-specific flavors to light-up more APIs or features.
You can also specify an optional OS version at the end of an OS-specific TFM, for example, net6.0-ios15.0. The version indicates which APIs are available to your app or library. It doesn't control the OS version that your app or library supports at run time. It's used to select the reference assemblies that your project compiles against, and to select assets from NuGet packages. Think of this version as the "platform version" or "OS API version" to disambiguate it from the run-time OS version.
When an OS-specific TFM doesn't specify the platform version explicitly, it has an implied value that can be inferred from the base TFM and platform name. For example, the default platform value for iOS in .NET 6 is 15.0, which means that net6.0-ios is shorthand for the canonical net6.0-ios15.0 TFM. The implied platform version for a newer base TFM may be higher, for example, a future net8.0-ios TFM could map to net8.0-ios16.0. The shorthand form is intended for use in project files only, and is expanded to the canonical form by the .NET SDK's MSBuild targets before being passed to other tools, such as NuGet.
The .NET SDK is designed to be able to support newly released APIs for an individual platform without a new version of the base TFM. This enables you to access platform-specific functionality without waiting for a major release of .NET. You can gain access to these newly released APIs by incrementing the platform version in the TFM. For example, if the iOS platform added iOS 15.1 APIs in a .NET 6.0.x SDK update, you could access them by using the TFM net6.0-ios15.1.
If your app references a package that has multiple assets for different TFMs, the assets that are closer in version number are preferred. For example, if your app targets net6.0-ios and the package offers assets for net6.0 and net5.0-ios, the net6.0 assets are used. For more information, see Precedences.
Although a platform-specific app or library is compiled against APIs from a specific version of that OS, you can make it compatible with earlier OS versions by adding the SupportedOSPlatformVersion property to your project file. The SupportedOSPlatformVersion property indicates the minimum OS version required to run your app or library. If you don't explicitly specify this minimum run-time OS version in the project, it defaults to the platform version from the TFM.
For your app to run correctly on an older OS version, it can't call APIs that don't exist on that version of the OS. However, you can add guards around calls to newer APIs so they are only called when running on a version of the OS that supports them. This pattern allows you to design your app or library to support running on older OS versions while taking advantage of newer OS functionality when running on newer OS versions.
The SupportedOSPlatformVersion value (whether explicit or default) is used by the platform compatibility analyzer, which detects and warns about unguarded calls to newer APIs. It's burned into the project's compiled assembly as an UnsupportedOSPlatformAttribute assembly attribute, so that the platform compatibility analyzer can detect unguarded calls to that assembly's APIs from projects with a lower SupportedOSPlatformVersion value. On some platforms, the SupportedOSPlatformVersion value affects platform-specific app packaging and build processes, which is covered in the documentation for those platforms.
Here is an example excerpt of a project file that uses the TargetFramework and SupportedOSPlatformVersion MSBuild properties to specify that the app or library has access to iOS 15.0 APIs but supports running on iOS 13.0 and above:
Target frameworks are specified in a project file. When a single target framework is specified, use the TargetFramework element. The following console app project file demonstrates how to target .NET 8:
When you specify multiple target frameworks, you may conditionally reference assemblies for each target framework. In your code, you can conditionally compile against those assemblies by using preprocessor symbols with if-then-else logic.
The following library project targets APIs of .NET Standard (netstandard1.4) and .NET Framework (net40 and net45). Use the plural TargetFrameworks element with multiple target frameworks. The Condition attributes include implementation-specific packages when the library is compiled for the two .NET Framework TFMs:
The build system is aware of preprocessor symbols representing the target frameworks shown in the Supported target framework versions table when you're using SDK-style projects. To convert a .NET Standard, .NET Core, or .NET 5+ TFM to a preprocessor symbol, replace dots and hyphens with an underscore, and change lowercase letters to uppercase (for example, the symbol for netstandard1.4 is NETSTANDARD1_4).
Yesterday I tested my first Cross-platform custom activity and the target framework is only net6.0. I created projects with different compatibility modes, Windows and Cross-platform. In both cases I could see and include my activity in the package manager. Does this mean that the target framework net6.0-windows7.0 always includes net6.0? Or the other way around, if a custom activity is marked with the attribute TargetFramework net6.0, can it always be executed with net6.0-windows7.0? Then net6.0 would always be a subset of net6.0-windows7.0.
Thanks for clarification.
3a8082e126