Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2013 为多个文件夹中的多个文件创建VS2013项目模板_Visual Studio 2013_Customization - Fatal编程技术网

Visual studio 2013 为多个文件夹中的多个文件创建VS2013项目模板

Visual studio 2013 为多个文件夹中的多个文件创建VS2013项目模板,visual-studio-2013,customization,Visual Studio 2013,Customization,我开始将其作为一个项目模板,但如果这不是合适的解决方案,请让我知道。当一个新的小部件被添加到项目中时,我试图自动创建几个文件(可能还有几个文件夹)。我使用的是MVP模式,因此每个小部件都有5个类(IModel、Model、IView、View和Presenter),每个类都有相同的基本名称,但位于不同的文件夹中。文件夹结构类似于 +Models +Interfaces + IModelOne + ModelOne + SubsetOne + Int

我开始将其作为一个项目模板,但如果这不是合适的解决方案,请让我知道。当一个新的小部件被添加到项目中时,我试图自动创建几个文件(可能还有几个文件夹)。我使用的是MVP模式,因此每个小部件都有5个类(IModel、Model、IView、View和Presenter),每个类都有相同的基本名称,但位于不同的文件夹中。文件夹结构类似于

+Models
    +Interfaces
      + IModelOne
    + ModelOne
    + SubsetOne
      + Interfaces
        + IModelThree
      + ModelThree
+Views
    + Interfaces
      + IViewOne
    + SubsetOne
      + Interfaces
        + IViewThree
      + ViewThree
+Presenters
    + PresenterOne
    + SubsetOne
      + PresenterThree
“模型”、“视图”和“演示者”文件夹具有相同的结构。我希望有一种方法可以将模板中的新项目添加到相同的结构中,基于1。)他们单击添加菜单项的位置(例如,如果他们右键单击Presenters->Substone并选择add new item,它会以某种方式意识到Substone是构建所有内容的“基本路径”),或者2。)允许用户输入“基本路径”通过一个向导类型的东西

不使用向导,我可以让它在模型、视图和演示者文件夹(或某些硬编码子目录)的顶层创建所有必要的文件。对于某些小部件(需要位于顶层的小部件),这是可以的,但它的使用将非常有限

我按照上的说明进行了设置。我在尝试使用向导时遇到的问题是,它会弹出一条消息,指示“值不在预期范围内”。“我尝试通过的步骤进行调试,但断点从未命中,它表示符号未加载。但是,向导类中的消息框从未显示,因此我怀疑错误不在向导类中。如果我能让它在我的机器上运行,我希望能够将它提供给团队中的其他开发人员使用

我的向导类代码:

/// <summary>
/// A wizard class to receive additional input from the
/// user before creating the set of MVP classes.
/// </summary>
public class MvpWizard : IWizard
{

    /// <summary>
    /// Runs custom wizard logic at the beginning of a template wizard run.
    /// </summary>
    /// <param name="automationObject">The automation object being used by the template 
    /// wizard.</param>
    /// <param name="replacementsDictionary">The list of standard parameters to be replaced.</param>
    /// <param name="runKind">A <see cref="T:Microsoft.VisualStudio.TemplateWizard.WizardRunKind"/> indicating 
    /// the type of wizard run.</param><param name="customParams">The custom parameters with which to 
    /// perform parameter replacement in the project.</param>
    public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary,
                           WizardRunKind runKind, object[] customParams)
    {
        MvpWizardForm form = new MvpWizardForm();

        try
        {
            form.ShowDialog();

            replacementsDictionary.Add("$BasePath$", form.BasePath);
            replacementsDictionary.Add("$PresenterPath$", form.PresenterPath);
        }
        catch (Exception e)
        {
            MessageBox.Show("An exception occured: ", e.Message);
        }
    }

    /// <summary>
    /// Runs custom wizard logic when a project has finished generating.
    /// </summary>
    /// <param name="project">The project that finished generating.</param>
    public void ProjectFinishedGenerating(Project project) {}

    /// <summary>
    /// Runs custom wizard logic when a project item has finished generating.
    /// </summary>
    /// <param name="projectItem">The project item that finished generating.</param>
    public void ProjectItemFinishedGenerating(ProjectItem projectItem) {}

    /// <summary>
    /// Indicates whether the specified project item should be added to the project.
    /// </summary>
    /// <returns>
    /// true if the project item should be added to the project; otherwise, false.
    /// </returns>
    /// <param name="filePath">The path to the project item.</param>
    public bool ShouldAddProjectItem(string filePath)
    {
        return true;
    }

    /// <summary>
    /// Runs custom wizard logic before opening an item in the template.
    /// </summary>
    /// <param name="projectItem">The project item that will be opened.</param>
    public void BeforeOpeningFile(ProjectItem projectItem) {}

    /// <summary>
    /// Runs custom wizard logic when the wizard has completed all tasks.
    /// </summary>
    public void RunFinished() {}
//
///用于接收来自的其他输入的向导类
///用户在创建MVP类集之前。
/// 
公共类MvpWizard:IWizard
{
/// 
///在模板向导运行开始时运行自定义向导逻辑。
/// 
///模板正在使用的自动化对象
///巫师。
///要替换的标准参数列表。
///指示
///运行向导的类型。要使用的自定义参数
///在项目中执行参数替换。
public void RunStarted(对象自动对象、字典替换Dictionary、,
WizardRunKind,对象[]customParams)
{
MvpWizardForm=新的MvpWizardForm();
尝试
{
form.ShowDialog();
replacementsDictionary.Add(“$BasePath$”,form.BasePath);
replacementsDictionary.Add(“$PresenterPath$”,form.PresenterPath);
}
捕获(例外e)
{
Show(“发生异常:”,e.Message);
}
}
/// 
///在项目完成生成后运行自定义向导逻辑。
/// 
///完成生成的项目。
public void ProjectFinishedGenerating(Project Project){}
/// 
///在项目项生成完成后运行自定义向导逻辑。
/// 
///完成生成的项目项。
public void projectItemFinishedGeneration(ProjectItem ProjectItem){}
/// 
///指示是否应将指定的项目项添加到项目中。
/// 
/// 
///如果项目项应添加到项目中,则为true;否则为false。
/// 
///项目项的路径。
公共bool ShouldAddProjectItem(字符串文件路径)
{
返回true;
}
/// 
///在模板中打开项目之前运行自定义向导逻辑。
/// 
///将打开的项目项。
在打开文件(ProjectItem ProjectItem){}之前公共无效
/// 
///在向导完成所有任务后运行自定义向导逻辑。
/// 
public void RunFinished(){}
以及.vstemplate代码:

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
   <TemplateData>
    <DefaultName>Mvp.cs</DefaultName>
     <Name>MVP item</Name>
     <Description>stuff</Description>
     <ProjectType>CSharp</ProjectType>
     <SortOrder>10</SortOrder>
     <Icon>__TemplateIcon.png</Icon>
  </TemplateData>
  <TemplateContent>
    <References />
     <ProjectItem SubType="" TargetFileName="Models/Interfaces/I$fileinputname$Model.cs" ReplaceParameters="true">ITestModel.cs</ProjectItem>
 <ProjectItem SubType="" TargetFileName="Models/$fileinputname$Model.cs" ReplaceParameters="true">TestModel.cs</ProjectItem>
 <ProjectItem SubType="" TargetFileName="Views/Interfaces/I$fileinputname$View.cs" ReplaceParameters="true">ITestView.cs</ProjectItem>
 <ProjectItem SubType="" TargetFileName="Views/$fileinputname$View.cs" ReplaceParameters="true">TestView.cs</ProjectItem>
     <ProjectItem SubType="" TargetFileName="Views/$fileinputname$View.Designer.cs" ReplaceParameters="true">TestView.Designer.cs</ProjectItem>
 <ProjectItem SubType="" TargetFileName="Presenters/$fileinputname$Presenter.cs" ReplaceParameters="true">TestPresenter.cs</ProjectItem>
 <CustomParameters>
       <CustomParameter Name="$Model$" Value="$fileinputname$Model"/>
       <CustomParameter Name="$ModelInterface$" Value="I$fileinputname$Model"/>
       <CustomParameter Name="$Presenter$" Value="$fileinputname$Presenter"/>
       <CustomParameter Name="$View$" Value="$fileinputname$View"/>
       <CustomParameter Name="$ViewInterface$" Value="I$fileinputname$View"/>
     </CustomParameters>
   </TemplateContent>
   <WizardExtension>
     <Assembly>MvpWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=37d8d03713727225</Assembly>
     <FullClassName>MvpWizard.MvpWizard</FullClassName>
   </WizardExtension>
 </VSTemplate>

Mvp.cs
MVP项目
东西
CSharp
10
__TemplateIcon.png
ITestModel.cs
TestModel.cs
ITestView.cs
TestView.cs
TestView.Designer.cs
TestPresenter.cs
MvpWizard,版本=1.0.0.0,区域性=中立,PublicKeyToken=37D8D037137225
MvpWizard.MvpWizard

有什么想法吗?TIA!

这篇文章提供了创建包含文件夹结构的模板的选项。

哦,伙计,如果这样做可行的话,那太棒了。我面临着同样的问题(为一个功能创建了很多文件),每次做同样愚蠢的工作都会感到恶心。。。