首先我们要添加<%@ Assembly Name="System.Design" %>命名空间。然后我们在模板中自定义一个属性,用来表示要存储的路径。其中我们使用了this.CodeTemplateInfo.DirectoryName得到当前模版所在路径作为默认路径。

private string _outputDirectory = String.Empty;
[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))] 
[Optional]
[Category("Output")]
[Description("The directory to output the results to.")]
public string OutputDirectory 
{
get
         {
// default to the directory that the template is located in
if (_outputDirectory.Length == 0) return this.CodeTemplateInfo.DirectoryName + "output\\";
return _outputDirectory;
         }
set
         {
if (!value.EndsWith("\\")) value += "\\";
                   _outputDirectory = value;
         } 
}

这样编译运行后我们就可以看到如下效果:

相关文章:

  • 2021-10-27
  • 2021-05-18
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-10
  • 2021-12-28
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
相关资源
相似解决方案