-netcf

将编译器设置为面向 .NET Compact Framework。

语法

-netcf

注解

此选项 -netcf 使 Visual Basic 编译器面向 .NET Compact Framework 而不是完整的 .NET Framework。 仅完整 .NET Framework 中提供的语言功能处于禁用状态。

-netcf 选项旨在与 -sdkpath 一起使用。 禁用 -netcf 的语言功能与目标 -sdkpath文件中不存在的语言功能相同。

注释

此选项 -netcf 在 Visual Studio 开发环境中不可用;仅在从命令行编译时才可用。 -netcf加载 Visual Basic 设备项目时会设置该选项。

此选项 -netcf 将更改以下语言功能:

  • 终止程序执行的 End <关键字> 语句 关键字被禁用。 以下程序在编译时编译和运行,-netcf但在编译时失败。-netcf

    Module Module1
        Sub Main()
            End   ' not valid to terminate execution with /netcf
        End Sub
    End Module
    
  • 已禁用所有形式的后期绑定。 遇到识别的后期绑定方案时,会生成编译时错误。 以下程序在编译时编译和运行,-netcf但在编译时失败。-netcf

    Class LateBoundClass
        Sub S1()
        End Sub
    
        Default Property P1(ByVal s As String) As Integer
            Get
            End Get
            Set(ByVal Value As Integer)
            End Set
        End Property
    End Class
    
    Module Module1
        Sub Main()
            Dim o1 As Object
            Dim o2 As Object
            Dim o3 As Object
            Dim IntArr(3) As Integer
    
            o1 = New LateBoundClass
            o2 = 1
            o3 = IntArr
    
            ' Late-bound calls
            o1.S1()
            o1.P1("member") = 1
    
            ' Dictionary member access
            o1!member = 1
    
            ' Late-bound overload resolution
            LateBoundSub(o2)
    
            ' Late-bound array
            o3(1) = 1
        End Sub
    
        Sub LateBoundSub(ByVal n As Integer)
        End Sub
    
        Sub LateBoundSub(ByVal s As String)
        End Sub
    End Module
    
  • “自动”、“Ansi”和“Unicode 修饰符”处于禁用状态。 Declare 语句的语法也修改为 Declare Sub|Function name Lib "library" [Alias "alias"] [([arglist])]。 以下代码显示了编译的效果 -netcf

    ' compile with: /target:library
    Module Module1
        ' valid with or without /netcf
        Declare Sub DllSub Lib "SomeLib.dll" ()
    
        ' not valid with /netcf
        Declare Auto Sub DllSub1 Lib "SomeLib.dll" ()
        Declare Ansi Sub DllSub2 Lib "SomeLib.dll" ()
        Declare Unicode Sub DllSub3 Lib "SomeLib.dll" ()
    End Module
    
  • 使用从 Visual Basic 中删除的 Visual Basic 6.0 关键字会在使用时 -netcf 生成不同的错误。 这会影响以下关键字的错误消息:

    • Open

    • Close

    • Put

    • Print

    • Write

    • Input

    • Lock

    • Unlock

    • Seek

    • Width

    • Name

    • FreeFile

    • EOF

    • Loc

    • LOF

    • Line

示例:

以下代码使用 .NET Compact Framework 编译 Myfile.vb ,使用 c 驱动器上 .NET Compact Framework 的默认安装目录中找到的 mscorlib.dll 和 Microsoft.VisualBasic.dll 版本。 通常,将使用最新版本的 .NET Compact Framework。

vbc -netcf -sdkpath:"c:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE " myfile.vb

另请参阅