您的位置:首页 > 其它

VS 自定义工程模板

2016-09-27 21:04 190 查看
 

1. 创建与删除向导

 

创建完一个向导工程后,不需要任何布暑,在本机上创建新工程时就能看到新的向导,这是什么原理?那我要怎么删除这个新建的向导呢?

 

新创建的向导有一部分存储在(拷贝到了):

C:\Users\libopc\Documents\Visual Studio2008\Wizards

这些*.vsz文件中使用了

Param="ABSOLUTE_PATH =E:\project\V2PluginWizard"

参数,能够直接定位到建立的那个向导工程目录上。

 

如果需要删除新建的向导,把这些文件清理掉即可。

 

 

 

2. 各种文件的作用与路径是怎么定的?

 

File

Description

Project.vsz

A text file that resembles the old .ini format. It identifies the wizard engine and provides context and optional custom parameters.

Project.vsdir

A text file that enables the Visual Studio shell to find the wizard and display it in the New Project dialog box.

HTML files (optional)

A wizard can contain a user interface (UI), which is an HTML interface. A wizard without a UI contains no HTML files.

If a wizard has a UI, each individual screen in the wizard is known as a page, and each page specifies UI features.

The default.htm file defines the first page in the wizard. Use the Number of pageslist box of Application Settings, Custom Wizard to specify additional
pages. Each additional page is defined by a Page_page-number.htm file, where page-numberranges from 2 through the number of pages that you specify.

Script files

The Custom Wizard creates a JScript file, default.js, for each wizard created. This file contains JScript functions that access the Visual C++ Wizard, Code, and Environment Object Models to customize a wizard. You can customize and add functions in your
wizard's default.js file.

Additionally, your wizard includes the common.js file, which contains commonly used JScript functions and is shared among all wizards, including the wizards used by Visual
C++ to create other project types. For more information, seeCustomizing C++ Wizards with Common JScript Functions.

Templates

A wizard's templates are a collection of text files that contain directives, which are parsed and inserted into the symbol table, depending on the wizard user's selections. The template text files are rendered according to the user input and added to the
project created by the wizard. The appropriate information is obtained by directly accessing the wizard control's symbol table.

Templates.inf

A text file that lists all templates associated with the project.

Default.vcxproj

An .xml file that contains the information about the project type.

Sample.txt

A template file that shows how your wizard directives are used.

ReadMe.txt

A template file that contains a summary of each file created by the Custom Wizard.

Images (optional)

You can provide any images, such as icons, GIFs, BMPs, and other HTML-supported image formats, to enhance the UI for your wizard. A wizard that has no UI does not require images.

Styles.css (optional)

A file that defines the styles for the UI. If your wizard does not have a user interface, the Custom Wizard does not create a .css file.

 

参考:Custom Parameters in the Wizard .VszFile

https://msdn.microsoft.com/en-us/library/cc9ss95t.aspx

 

ABSOLUTE_PATH 与RELATIVE_PATH

如果没找到ABSOLUTE_PATH,则会使用RELATIVE_PATH,这个相对目录是相对于PRODUCT_INSTALLATION_DIR\VCWizards

 

START_PATH = ABSOLUTE_PATH或者RELATIVE_PATH。

 

HTML文件的默认路径为: START_PATH\HTML\LANGUAGE,这个路径可以在.vsz中使用HTML_PATH参数修改。

Images的默认路径为:START_PATH\Images,这个路径可以在.vsz中使用IMAGES_PATH参数修改。

Scripts的默认路径为:START_PATH\Scripts,这个路径可在以.vsz中使用SCRIPT_PATH参数修改

 

3. window.external指哪个对象

 

Wizardand Environment Object Models

 

4. 各种HTML控件对应的SYMBOL写法

 

.vsz中的parameters和HTML文件中的symbol section一起构建成了一个symbol table。

    Symbol NAME属性与控件的ID属性相对应

 

l  编辑框、静态文本:

<SYMBOL NAME='WIZARD_DIALOG_TITLE'TYPE=text VALUE='Console Application Wizard'></SYMBOL>

 

l  复选框、单选框:

<SYMBOL NAME='EMPTY_PROJECT'TYPE=checkbox VALUE=false></SYMBOL>

 

l  下拉列表

<SYMBOLNAME='SAMPLE_LISTBOX' TYPE=select-one VALUE='option1'>

</SYMBOL>

 

控件写法:

<SELECTCLASS="sideBtn" SIZE="1"

ID="SAMPLE_LISTBOX"TITLE="Sample list box.">

    <OPTIONVALUE="option1" SELECTED>option 1</OPTION>

    <OPTIONVALUE="option2">option 2</OPTION>

 </SELECT>

 

5. 如何在js中访问这些SYMBOLS

 

if(window.external.FindSymbol('DOCUMENT_FIRST_LOAD'))

{

    ...

}

 

var strProjectPath= wizard.FindSymbol('PROJECT_PATH');

varstrProjectName = wizard.FindSymbol('PROJECT_NAME');

 

 

6. 模板文件中的语法是什么

TemplateDirectives

https://msdn.microsoft.com/en-us/library/8x8by37d.aspx

 

[!directiveparams]

以 [! 开头,以 ] 结尾

 

Directive

Description

[! if ]

Begins a control structure to check for a condition.

[! else ]

Part of the [! if ] control structure. Checks for another condition.

[! endif ]

Ends the definition of an [! if ] control structure.

[! output ]

Can be used in the following two ways:

[! output "string" ] gives you the string.
[! output SYMBOL_STRING ] gives you the value of the symbol SYMBOL_STRING.
[! loop ]

Can be used in the following two ways:

[! loop = 5 ]
[! loop = NUM_OF_PAGES ] where NUM_OF_PAGES is a symbol with a numeric value.

[! endloop ]

Ends a loop structure.

 

在 if 中可以使用:

+

-  

=

!=  

==  

||  

&& 

!

例如[!if SYMBOL_STRING != 0]

在 inf 文件中也可以使用这套语法来判断包含哪些文件

 

7. JS文件要怎么玩

Common.js是唯一的,Default.js是每个工程唯一的。

 

Default.js文件是在点击了’完成’按钮之后被加载的。

 

Bydefault, the project's Default.js file includes the following functions:

 

Function name

Description

AddConfig

Adds the project's configurations. You can supply compiler and linker settings.

AddFilesToCustomProj

When the user clicks Finish, adds the specified files to the project.

AddFilters

When the user clicks Finish, adds the specified source filters to the project.

CreateCustomProject

When the user clicks Finish, creates the project at the specified location.

CreateCustomInfFile

Creates the project's Templates.inf file.

DelFile

Deletes the specified file.

GetTargetName

Get the name of the specified file.

OnFinish

Called by the wizard when the user clicks Finish to create the project, add files and filters, render templates, and set the configuration.

PchSettings

Sets the precompiled header settings. See SetCommonPchSettings in the Common.js reference for more information.

 

 

8. vsdir文件是什么东西

 

该文件定义了向导项目中需显示的项以及在对话框中要显示的属性,诸如:名称,描述,图标,缺省项文件名。对于其中包含的每一各向导项,则通过相应的.vsz文件予以说明

 

格式:

vsz相对路径 | 资源dll GUID | 显示名称 | 排序值,越小越靠前 | 描述信息 | (unknown) | (unknown) | 默认工程名

 

如果没有vsdir文件,则显示为:

 

 

https://msdn.microsoft.com/zh-cn/library/aa291929(v=vs.71).aspx

https://msdn.microsoft.com/zh-cn/library/bb166192.aspx

 

可为 VSDir 文件中的每个记录指定下列字段:

字段

意义

RelPathName

必选项。向导的 .vsz 文件的名称,如 MyWizard.vsz。

{clsidPackage}

可选项。表示产品的 GUID,该产品(如 Visual C++)带有的 DLL 中包含本地化资源。通常,对于符合第三方向导的 VSDir 文件,此字段为空。

LocalizedName

可选项。这是向导或模板的可本地化的名称以及出现在“添加项”对话框中的名称。它可以是字符串或 #ResID 形式的资源标识符。

SortPriority

必选项。表示向导的排序顺序和相对优先级的整数,1 为最高。例如,如果此项为“1”,那么它出现在其他 1 之后和所有 2 或更低级别之前。

Description

必选项。当选定项后,将在“添加项”对话框中显示的模板或向导的可本地化说明。它可以是字符串或 #ResID 形式的资源标识符。仅应用于模板文件,不应用于文件夹。

DLLPath 或 {clsidPackage}

必选项。指定到 DLL 或 EXE 文件的完整路径,或产品的 GUID,该产品所带的 .dll 文件包含要为向导加载的图标。该图标使用给定的IconResourceId 作为 DLL/EXE 文件外部的资源加载。此设置覆盖图标位置的 {clsidPackage}(如果指定了)。仅应用于模板文件,不应用于文件夹。

IconResourceId

可选项。DLL 文件内确定要显示的图标的资源标识符。如果未定义图标,环境用默认图标替代与该项具有相同扩展名的文件。仅应用于模板文件,不应用于文件夹。

Flags

必选项。请参见下面的“标志”说明和表。仅应用于模板文件,不应用于文件夹。

SuggestedBaseName

必选项。向导的默认名称,显示在对话框的“名称”字段中。这是字符串或 #ResID 形式的资源标识符。如果该名称不是唯一的,那么环境将为该名称追加一个整数。例如,MyFile.asp 可能会更改为MyFile1.asp。如果未提供名称,那么使用“Project”。仅应用于模板文件,不应用于文件夹。

 

注意   

任何没有有含义的数据的非必选字段应包含零 (0) 作为占位符。
如果未提供本地化名称,则使用相对路径名。
如果未定义图标,则 IDE 用该扩展名替换文件的默认图标。
如果未提供建议的基名称,则使用“Project”。
 

 

8. 怎么调试default.js

 

https://msdn.microsoft.com/en-us/library/aa730846(v=vs.80).aspx

一共需要启用两个devenv.exe。

1. 首先在devenv1中,defalut.js中打一个断点,

2. 再开启一个deven2,创建一个我们的向导工程。

3. 在devevn1中,attach到devenv2上。

4. 点击devenv2中向导工程的确定按钮,此时devenv1断点中断。

 

点击确定按钮时,会调用

functionOnFinish(selProj, selObj)

函数。

 

每次修改完default.js之后,再想调试,需要关闭除其它devenv.exe,再开启一个devenv.exe进行attach.

 

Debugging

To debugthe script in the wizard's HTML and script files, you must first enable scriptdebugging. This can be done by the following steps:

In Internet Explorer, click the Tools menu and choose Internet Options.

Click the Advanced tab.
Under the Browsing category, clear the Disable Script Debugging checkbox.
Once youdo this, you can attach another Visual Studio process to your current VisualStudio process as a script debugger. You can set breakpoints in your scriptblocks within your HTML files and default.js and other script files.

 

 

9. 拷贝模板文件时,如何重命名?

default.js中 GetTargetName函数专门用于实现文件重命名。

一般是将需要替换的名字以root代替,然后在js中replace,如下:

 

functionGetTargetName(strName, strProjectName)

{

    var strTarget = strName;

    strTarget =strTarget.replace("root", strProjectName)

.toLowerCase();

    return strTarget;

}

 

10. 如何将文件添加到指定的filter下面,而不仅按后缀进行归纳?

MSDN: VCProjectObject Properties, Methods, and Events

https://msdn.microsoft.com/en-us/library/aa713034(v=vs.71).aspx

 

不在function AddFilters(proj)中添加filter,而是在AddFilesToCustomProj去添加,拿到filter对象后,调用filter对象的AddFile即可。

同时需要修改inf文件的规则:

 

[01.Inc]

[02. UI]

ui\root_ui.h

ui\root_ui.cpp

解析到[xxx]就创建一个新的filter,然后将后面的文件添加到该filter下面

 

11. 如何将文件添加到指定位置,不在本工程目录下面

 再修改inf文件的格式,增加拷贝到的目录属性:

[01. Inc]

plugin_root_inc.h ->..\..\Include\V2\

12. 如何配置工程属性

 

参见

functionAddConfig(proj, strProjectName)

functionSetCommonConfigData(config, bDebug)

 

 

 

13. 预编译头怎么设置

functionPchSettings(proj)

{

    try

    {

       var files = proj.Object.Files;

       var fStdafx =files("StdAfx.cpp");

 

       var config = fStdafx.FileConfigurations("Debug");

       config.Tool.UsePrecompiledHeader =pchCreateUsingSpecific;

      

       var config =fStdafx.FileConfigurations("Release");

       config.Tool.UsePrecompiledHeader =pchCreateUsingSpecific;

    }

    catch(e)

    {

       throw e;

    }

}

 

 

14. 拷贝过去的文件,中文变成乱码怎么解决

    将模板文件用记事本修改为utf8编码保存即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  向导 wizard