Condividi tramite


Develop for multiple platforms with .NET Framework

You can develop apps for both Microsoft and non-Microsoft platforms by using .NET Framework and Visual Studio.

Note

.NET Framework 4.8 is the last version of .NET Framework. However, .NET Framework will continue to be serviced with monthly security and reliability bug fixes. Additionally, it will continue to be included with Windows, with no plans to remove it. You don't need to migrate your .NET Framework apps, but for new development, use .NET 5.0 or later.

Options for cross-platform development

Important

We strongly discourage the use of portable class libraries in new application development, because they target only a very specific subset of .NET implementations. If you're building a reusable library to share code between .NET Framework and other .NET implementations, the recommended replacement is a .NET Standard 2.0 library. Otherwise, use .NET 5 or later. For more information, see .NET Standard.

To develop for multiple platforms, you can share source code or binaries, and you can make calls between .NET Framework code and Windows Runtime APIs.

If you want to... Use...
Share source code between Windows Phone 8.1 and Windows 8.1 apps Shared projects (Universal Apps template in Visual Studio 2013, Update 2).

- Currently no Visual Basic support.
- You can separate platform-specific code by using #if statements.

For details, see:

- Start coding
- Using Visual Studio to build Universal XAML Apps (blog post)
- Using Visual Studio to Build XAML Converged Apps (video)
Share binaries between apps that target different platforms Portable Class Library projects for code that is platform-agnostic.

- This approach is typically used for code that implements business logic.
- You can use Visual Basic or C#.
- API support varies by platform.
- Portable Class Library projects that target Windows 8.1 and Windows Phone 8.1 support Windows Runtime APIs and XAML. These features aren't available in older versions of the Portable Class Library.
- If needed, you can abstract out platform-specific code by using interfaces or abstract classes.

For details, see:

- Portable Class Library
- How to Make Portable Class Libraries Work for You (blog post)
- Using Portable Class Library with MVVM
- App Resources for Libraries That Target Multiple Platforms
- .NET Portability Analyzer (Visual Studio extension)
Share source code between apps for platforms other than Windows 8.1 and Windows Phone 8.1 Add as link feature.

- This approach is suitable for app logic that's common to both apps but not portable, for some reason. You can use this feature for C# or Visual Basic code.
For example, Windows Phone 8 and Windows 8 share Windows Runtime APIs, but Portable Class Libraries do not support Windows Runtime for those platforms. You can use Add as link to share common Windows Runtime code between a Windows Phone 8 app and a Windows Store app that targets Windows 8.

For details, see:

- Share code with Add as Link
- How to: Add Existing Items to a Project
Write Windows Store apps using the .NET Framework or call Windows Runtime APIs from .NET Framework code Windows Runtime APIs from your .NET Framework C# or Visual Basic code, and use the .NET Framework to create Windows Store apps. You should be aware of API differences between the two platforms. However, there are classes to help you work with those differences.

For details, see:

- .NET Framework Support for Windows Store Apps and Windows Runtime
- Passing a URI to the Windows Runtime
- WindowsRuntimeStreamExtensions
- WindowsRuntimeSystemExtensions
Build .NET Framework apps for non-Microsoft platforms Portable Class Library reference assemblies in the .NET Framework, and a Visual Studio extension or third-party tool such as Xamarin.

For details, see:

- Portable Class Library now available on all platforms. (blog post)
- Xamarin documentation
Use JavaScript and HTML for cross-platform development Universal App templates in Visual Studio 2013, Update 2 to develop against Windows Runtime APIs for Windows 8.1 and Windows Phone 8.1. Currently, you can't use JavaScript and HTML with .NET Framework APIs to develop cross-platform apps.

For details, see:

- JavaScript Project Templates
- Porting a Windows Runtime app using JavaScript to Windows Phone