visual studio – custom tool 的相關資料

來源:互聯網
上載者:User

  什麼是custom tool? 對visual studio比較熟悉的人, 可能都曾經注意到過, 自從VS2002開始, solution explorer中檔案的properties中, 都有一個Custom Tool屬性.

  例如, 我們在VS中通過菜單Project -> Add New Item -> Data -> DataSet建立一個DataSet1.xsd檔案, 此時, 我們發現DataSet1.xsd檔案的properties中的custom tool屬性為MSDataSetGenerator.

  當我們更改DataSet1.xsd檔案時, 仔細觀察, 我們發現與之相對應的DataSet1.Designer.cs檔案中也會產生做出相應的更新.
如果我們刪除此檔案, 再次儲存DataSet1.xsd, 將看到DataSet1.Designer.cs又出現了.
然後, 我們再次刪除DataSet1.Designer.cs檔案, 去掉DataSet1.xsd檔案properties中的Custom Tool屬性, 再次儲存, DataSet1.Designer.cs卻沒有出現了.

同樣, 具有Custom Tool屬性的*dbml檔案也有相同的特性.

於是, 我們有理由相信*.Designer.cs檔案的出現, 和對應檔案的Custom Tool屬性有莫大的關係.

  實際上, Custom Tool屬性的作用是, 當具有此屬性的檔案在儲存時, 將調用指定的介面來處理此檔案. 例如, 根據DataSet1.xsd檔案產生相應的DataSet1.Designer.cs檔案. 另一個常見的例子是: 根據wsdl產生WebService代理類.

  或許, 如果我們合理的利用此介面, 可為我們的工作剩下不少的時間.

 

以下是MSDN關於此介面的資料.

Implementing Single File Generators:
http://msdn2.microsoft.com/en-us/library/s686w8yb(VS.80).aspx

    A custom tool — sometimes referred to as a single file generator — can be used to extend the Visual Basic, Visual C#, and Visual J# project systems in Visual Studio. A custom tool is a COM component that implements the IVsSingleFileGenerator interface. Using this interface, a custom tool transforms a single input file into a single output file. The result of the transformation may be source code, or any other output that is useful. Two examples of custom tool-generated code files are code generated in response to changes in a visual designer and files generated using Web Services Description Language (WSDL).

    When a custom tool is loaded, or the input file is saved, the project system calls the Generate method, and passes a reference to a IVsGeneratorProgress callback interface, whereby the tool can report its progress to the user.

    The output file that the custom tool generates is added to the project with a dependency on the input file. The project system automatically determines the name of the output file, based on the string returned by the custom tool's implementation of DefaultExtension.

    A custom tool must implement the IVsSingleFileGenerator interface. Optionally, custom tools support the IObjectWithSite interface to retrieve information from sources other than the input file. In any case, before you can use a custom tool, you must register it with the system or in the Visual Studio local registry. For more information on registering custom tools, see Registering Single File Generators.

 

Assembly: Microsoft.VisualStudio.Shell.Interop (in microsoft.visualstudio.shell.interop.dll)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.