共用方式為


HOW TO:編譯工作流程

您可以用下列三種方法建構工作流程:

  • 透過宣告使用副檔名為 .xoml 之工作流程標記檔中的工作流程標記。 然後,您可以使用工作流程編譯器編譯這個工作流程檔案,或是透過主應用程式不經編譯來將該檔案傳遞至工作流程執行階段引擎。 這也就是「無程式碼工作流程撰寫」(No-code Workflow Authoring)。 如需詳細資訊,請參閱使用工作流程標記。 所建立檔案的副檔名會是 .xoml。

  • 標記檔可用於宣告工作流程,但接著會由包含實作邏輯的程式碼檔案來編譯標記檔。 這也就是「程式碼分離工作流程撰寫」(Code-separation Workflow Authoring)。 在此狀況下,所建立檔案的副檔名會是 .xoml 和 .xoml.cs 或 .xoml.vb。

  • 透過在程式碼檔案中使用 Windows Workflow Foundation 物件模型。 這也就是「僅限程式碼工作流程撰寫」(Code-only Workflow Authoring)。 在此狀況下,所建立檔案的副檔名為 C# 或 Visual Basic 標準原始程式碼檔的副檔名。 這些檔案也會經過編譯。

編譯處理程序

編譯工作流程時,編譯處理程序會執行下列程序:

  • 執行驗證,以根據工作流程活動為自己設定的規則確認這些活動是有效的。 如果驗證錯誤,則編譯器會傳回錯誤清單。

  • 從輸入編譯器的標記定義產生部分類別。

  • 產生程式碼來協助活動的執行階段執行。 產生事件訂閱來協助活動知道它們所包含的活動何時完成執行。

  • 從標記檔產生的部分類別和從程式碼檔產生的部分類別會進入 .NET Framework C# 或 Visual Basic 編譯器。 這個程序的輸出為 .NET 組件 WorkflowSample.dll。 您可以部署這個組件來執行工作流程。

使用 wfc.exe 工作流程命令列編譯器

Windows Workflow Foundation 提供名為 wfc.exe 的命令列工作流程編譯器。 Windows Workflow Foundation 也提供一組公用型別,這組型別會支援自訂編譯器開發的工作流程編譯。 這些公用型別與 wfc.exe 內部使用的型別相同。 您可以使用 WorkflowCompiler 類別來建立自訂版的編譯器。

您也可以使用 WorkflowCompiler 類別來編譯工作流程,如下列簡易範例所示。

WorkflowCompiler compiler = new WorkflowCompiler();
WorkflowCompilerParameters param = new WorkflowCompilerParameters();
compiler.Compile(param, new string[] { "MainWorkflow.xoml" });

如需詳細資訊,請參閱 Windows Workflow Foundation 類別庫參考中 WorkflowCompiler 類別。

編譯器選項

wfc.exe 工作流程命令列編譯器選項記載在下列程式碼樣式主題中。

Microsoft (R) Windows Workflow Compiler version 3.0.0.0
Copyright (C) Microsoft Corporation 2005. All rights reserved.

                  Windows Workflow Compiler Options

wfc.exe <Xoml file list> /target:assembly [<vb/cs file list>] [/language:...] 
        [/out:...] [/reference:...] [/library:...] [/debug...] [/nocode...] 
         [/checktypes...] [/resource:<resource info>]

                        - OUTPUT FILE -
/out:<file>             Output file name
/target:assembly        Build a Windows Workflow assembly (default).
                        Short form: /t:assembly
/target:exe             Build a Windows Workflow application.
                        Short form: /t:exe
/delaysign[+|-]         Delay-sign the assembly using only the public portion
                        of the strong name key.
/keyfile:<file>         Specifies a strong name key file.
/keycontainer:<string>  Specifies a strong name key container.

                        - INPUT FILES -
<Xoml file list>        Xoml source file name(s).
<vb/cs file list>       Code-beside file name(s).
/reference:<file list>  Reference metadata from the specified assembly file(s).
                        Short form is '/r:'.
/library:<path list>    Set of directories where to lookup for the references.
                        Short form is '/lib:'.
/resource:<resinfo>     Embed the specified resource. Short form is '/res:'.
                        resinfo format is <file>[,<name>[,public|private]].

Rules and freeform layout files must be embedded as assembly resources.
The resource name is constructed by using the namespace and type name
of the activity. For example, an activity named "MyActivity" in namespace
"WFProject" would require resource names "WFProject.MyActivity.rules"
and/or "WFProject.MyActivity.layout".

                        - CODE GENERATION -
/debug[+|-]             Emit full debugging information. The default is '+'.
/nocode[+|-]            Disallow code-beside model.
                        The default is '-'. Short form is '/nc:'.
/checktypes[+|-]        Check for permitted types in wfc.exe.config file.
                        The default is '-'. Short form is '/ct:'.

                        - LANGUAGE -
/language:[cs|vb]       The language to use for the generated class.
                        The default is 'CS' (C#). Short form is '/l:'.
/rootnamespace:<string> Specifies the root Namespace for all type declarations.
                        Valid only for 'VB' (Visual Basic) language.
                        Short form is '/rns:'.

                        - MISCELLANEOUS -
/help                   Display this usage message. Short form is '/?'.
/nologo                 Suppress compiler copyright message. Short form is '/n'.

/nowarn                 Ignore compiler warnings. Short form is '/w'.

請參閱

參考

WorkflowCompiler

概念

工作流程撰寫模式
序列化自訂活動
HOW TO:序列化工作流程

Footer image

Copyright © 2007 by Microsoft Corporation. All rights reserved.