我目前正在创建一个项目模板,我想知道在项目创建后是否可以执行PowerShell脚本(类似于NuGet包中的 install.ps1 )。 / p>
如果没有实现我自己的IWizard
,有机会这样做吗?答案 0 :(得分:2)
好的......我尝试了很多东西,但最后我最终得到了自定义IWizard。
public class InitScriptWizard : IWizard
{
public void RunStarted(
object automationObject,
Dictionary<string, string> replacementsDictionary,
WizardRunKind runKind,
object[] customParams)
{ }
public void ProjectFinishedGenerating(Project project)
{
var script =
project.ProjectItems.FindProjectItem(
item => item.Name.Equals("init.ps1"));
if (script == null)
{
return;
}
var process =
System.Diagnostics.Process.Start(
"powershell",
string.Concat(
"-NoProfile -ExecutionPolicy Unrestricted -File \"",
script.FileNames[0],
"\""));
//if (process != null)
//{
// process.WaitForExit();
//}
//script.Delete();
}
public void ProjectItemFinishedGenerating(ProjectItem projectItem)
{ }
public bool ShouldAddProjectItem(string filePath)
{
return true;
}
public void BeforeOpeningFile(ProjectItem projectItem)
{ }
public void RunFinished()
{ }
}