-netcf

設定編譯器以 .NET Compact Framework 為目標。

語法

-netcf

備註

選項 -netcf 會使 Visual Basic 編譯器以 .NET Compact Framework 為目標,而不是完整 .NET Framework。 只在完整 .NET Framework 中出現的語言功能已停用。

-netcf 選項的設計目的是要與 -sdkpath 搭配使用。 -netcf 所停用的語言功能不是以 -sdkpath 為目標檔案中的相同語言功能。

注意

-netcf 選項在 Visual Studio 開發環境中無法使用;只有在從命令列編譯時才可用。 載入 Visual Basic 裝置專案時會設定 -netcf 選項。

-netcf 選項會變更下列語言功能:

  • End< 關鍵字 >Statement 關鍵字已停用,該關鍵字會終止執行程式。 下列程式在沒有 -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
    
  • AutoAnsiUnicode 修飾詞已停用。 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

另請參閱