Visual Basic 和 .NET StandardVisual Basic and .NET Standard

Xamarin Android 和 iOS 项目不支持本机支持 Visual Basic;但是,开发人员可以使用.NET Standard库将现有 Visual Basic 代码迁移到 Android 和 iOS,或在 Visual Basic 中编写其应用程序逻辑的重要部分。Xamarin Android and iOS projects do not natively support Visual Basic; however developers can use .NET Standard libraries to migrate existing Visual Basic code to Android and iOS, or to write significant portion of their application logic in Visual Basic. Xamarin。窗体应用程序可以完全在 Visual Basic 中创建(自定义呈现器、依赖项服务和 XAML 代码隐藏)。Xamarin.Forms applications can be created entirely in Visual Basic (excluding custom renderers, dependency services, and XAML code-behind).


若要创建和编译 Visual Basic .NET Standard 库,必须在 Windows 上使用 Visual Studio (Visual Studio 2017 或更高版本)。To create and compile Visual Basic .NET Standard libraries you must use Visual Studio on Windows (Visual Studio 2017 or newer).


仅可使用 Visual Studio 创建和编译 Visual Basic 库。Visual Basic libraries can only be created and compiled using Visual Studio. Xamarin 和 Xamarin 不支持 Visual Basic 语言。Xamarin.Android and Xamarin.iOS do not support the Visual Basic language.

如果只在 Visual Studio 中工作,则可以从 Xamarin 和 Xamarin 项目引用 Visual Basic 项目。If you work solely in Visual Studio you can reference the Visual Basic project from Xamarin.Android and Xamarin.iOS projects.

如果你的 Android 和 iOS 项目还必须加载到 Visual Studio for Mac 应从 Visual Basic 程序集引用输出程序集。If your Android and iOS projects must also be loaded in Visual Studio for Mac you should reference the output assembly from the Visual Basic assembly.

创建 Visual Basic.NET .NET Standard 库Creating a Visual Basic.NET .NET Standard library

本部分介绍如何使用 Visual Studio 2019 创建 Visual Basic .NET Standard 库。This section walks through how to create a Visual Basic .NET Standard library using Visual Studio 2019. 然后,可以在其他项目(包括 Xamarin、Xamarin 和 Xamarin)中引用该库。The library can then be referenced in other projects, including Xamarin.Android, Xamarin.iOS, and Xamarin.Forms apps.

在 Visual Studio 中添加 Visual Basic .NET Standard 库时,必须注意选择正确的项目类型:When adding a Visual Basic .NET Standard library in Visual Studio you must be careful to choose the correct project type:

  1. 从 Visual Studio 2019 中选择 "创建新项目"。From Visual Studio 2019 choose Create a new project.

  2. 键入 " Visual Basic 库" 以筛选项目选项,然后选择 "类库 (.NET Standard) " 选项和 "Visual Basic" 图标:Type Visual Basic library to filter the project options and choose the Class Library (.NET Standard) option with the Visual Basic icon:

    Visual Basic 库筛选器Filter for Visual Basic library

  3. 在下一个屏幕上,键入项目的名称,然后按 "创建"。On the next screen, type a name for the project and press Create.

  4. Visual Basic 项目将显示如下所示的解决方案资源管理器中:The Visual Basic project will appear as shown in the Solution Explorer like this:

    空 Visual Basic 项目Empty Visual Basic project

项目现已准备好 Visual Basic 要添加的代码。The project is now ready for Visual Basic code to be added. .NET Standard 项目可以由其他项目(应用程序项目或库项目)引用。.NET Standard projects can be referenced by other projects (application projects or library projects).


本文演示了如何使用 Visual Studio 在 Xamarin 应用程序中使用 Visual Basic 代码。This article has demonstrated how consume Visual Basic code in Xamarin applications using Visual Studio. 尽管 Xamarin 不支持直接 Visual Basic,但将 Visual Basic 编译到 .NET Standard 库允许将使用 Visual Basic 编写的代码包含在 Android 和 iOS 应用中。Even though Xamarin does not support Visual Basic directly, compiling Visual Basic into a .NET Standard library allows code written with Visual Basic to be included in Android and iOS apps.

以下页面说明了如何在本机或 Xamarin 应用程序中使用 Visual Basic.NET .NET Standard 库。The following pages describe how to use Visual Basic.NET .NET Standard libraries in native or Xamarin.Forms apps: