如何在多项目 .vstemplate 中包含外部文件?

发布于 2024-09-13 08:01:22 字数 803 浏览 1 评论 0原文

我正在创建一个 VS2010 多项目模板,并尝试从 vstemplate 添加一个文件(.hgignore)到解决方案(而不是项目)。

我尝试了这个,但它不起作用:

< VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup">

    < TemplateData>...< /TemplateData>

    < TemplateContent >

        < ProjectItem> .hgignore < /ProjectItem >

        < ProjectCollection >       

            < ProjectTemplateLink ProjectName="$safeprojectname$.xxx">....< /ProjectTemplateLink>
            < ProjectTemplateLink ProjectName="$safeprojectname$.xxx">....< /ProjectTemplateLink>

        < /ProjectCollection>

    < /TemplateContent>

< /VSTemplate>

非常感谢你

PS:我无法在编辑器中创建正确的 XML 标签,所以我不得不添加空格...

I'm creating a VS2010 multi project template and I'm trying to make add a file (.hgignore) to the solution (not into a project) from the vstemplate.

I tried this but it doesn't work :

< VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup">

    < TemplateData>...< /TemplateData>

    < TemplateContent >

        < ProjectItem> .hgignore < /ProjectItem >

        < ProjectCollection >       

            < ProjectTemplateLink ProjectName="$safeprojectname$.xxx">....< /ProjectTemplateLink>
            < ProjectTemplateLink ProjectName="$safeprojectname$.xxx">....< /ProjectTemplateLink>

        < /ProjectCollection>

    < /TemplateContent>

< /VSTemplate>

Thank you very much

PS : I can't manage to make correct XML tag in the editor so I had to add white space...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦冥 2024-09-20 08:01:22

没有内置的方法可以做到这一点。但是,VSTemplate 向导引擎支持可扩展性模型,使您可以在解决方案/项目创建过程中运行自定义逻辑。您需要实现一个实现 IWizard 接口,然后在 .vstemplate 文件中添加WizardExtension 元素

查看 Craig Skibo 在 此问题上的回答MSDN 论坛问题,了解有关通过 IWizard.RunFinished 方法使用 DTE 自动化 API 添加解决方案项的详细信息。

There is no built-in way to do this. However, the VSTemplate wizard engine supports an extensibility model that lets you run custom logic during the solution/project creation process. You need to implement a class that implements the IWizard interface and then add a WizardExtension element in your .vstemplate file.

Check out Craig Skibo's answer on this MSDN forum question for the details on using the DTE automation API from your IWizard.RunFinished method to add a solution item.

罗罗贝儿 2024-09-20 08:01:22

可以通过 IWizard 以编程方式执行此操作。

示例向导,从 VSIX 复制 Nuget.Config(通过“包含在 VSIX 中”属性包含):

class AppCustomizationWizard : IWizard
{
    private const string NugetConfig = "Nuget.Config";

    private static string GetVsixFullPath(string filename)
    {
        var vsixDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
        if (string.IsNullOrEmpty(vsixDir))
        {
            return null;
        }

        return Path.Combine(
            vsixDir,
            filename
        );
    }

    private static void CopyNugetConfig(Dictionary<string, string> replacementsDictionary)
    {
        var solutionDir = replacementsDictionary["$solutiondirectory$"];
        var vsixNugetConfig = GetVsixFullPath(NugetConfig);
        if (solutionDir != null && vsixNugetConfig != null)
        {
            File.Copy(vsixNugetConfig, Path.Combine(solutionDir, NugetConfig));
        }
    }

    public void BeforeOpeningFile(ProjectItem projectItem)
    {
    }

    public void ProjectFinishedGenerating(Project project)
    {
    }

    public void ProjectItemFinishedGenerating(ProjectItem projectItem)
    {
    }

    public void RunFinished()
    {
    }

    public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary,
        WizardRunKind runKind, object[] customParams)
    {
        XElement wizardInfo = XElement.Parse(replacementsDictionary["$wizarddata$"]);
        XNamespace defaultNamespace = wizardInfo.GetDefaultNamespace();
        string itemType = wizardInfo.Element(defaultNamespace + "Type").Value;

        if (itemType == "Application")
        {
            CopyNugetConfig(replacementsDictionary);
        }
    }

    public bool ShouldAddProjectItem(string filePath)
    {
        return true;
    }
}

It is possible to do this programmatically via IWizard.

Example Wizard, which copies Nuget.Config from VSIX(which is included via "Include in VSIX" property):

class AppCustomizationWizard : IWizard
{
    private const string NugetConfig = "Nuget.Config";

    private static string GetVsixFullPath(string filename)
    {
        var vsixDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
        if (string.IsNullOrEmpty(vsixDir))
        {
            return null;
        }

        return Path.Combine(
            vsixDir,
            filename
        );
    }

    private static void CopyNugetConfig(Dictionary<string, string> replacementsDictionary)
    {
        var solutionDir = replacementsDictionary["$solutiondirectory
quot;];
        var vsixNugetConfig = GetVsixFullPath(NugetConfig);
        if (solutionDir != null && vsixNugetConfig != null)
        {
            File.Copy(vsixNugetConfig, Path.Combine(solutionDir, NugetConfig));
        }
    }

    public void BeforeOpeningFile(ProjectItem projectItem)
    {
    }

    public void ProjectFinishedGenerating(Project project)
    {
    }

    public void ProjectItemFinishedGenerating(ProjectItem projectItem)
    {
    }

    public void RunFinished()
    {
    }

    public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary,
        WizardRunKind runKind, object[] customParams)
    {
        XElement wizardInfo = XElement.Parse(replacementsDictionary["$wizarddata
quot;]);
        XNamespace defaultNamespace = wizardInfo.GetDefaultNamespace();
        string itemType = wizardInfo.Element(defaultNamespace + "Type").Value;

        if (itemType == "Application")
        {
            CopyNugetConfig(replacementsDictionary);
        }
    }

    public bool ShouldAddProjectItem(string filePath)
    {
        return true;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文