VSIX with Project Templates and NuGet Packages

前端 未结 3 2043
花落未央
花落未央 2020-12-10 18:46

I have been following this post about how to build a VSIX project that will add some custom MVC project types:

http://www.asp.net/mvc/tutorials/mvc-4/custom-mvc-temp

3条回答
  •  孤城傲影
    2020-12-10 19:14

    To download latest versions of NuGet packages plus all their dependencies add a following class to your vsix:

    public class MyProjectWizard : IWizard
    {
        IEnumerable _packages;
    
        public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            if (customParams.Length > 0) {
                var vstemplate = XDocument.Load((string)customParams[0]);
                _packages = vstemplate.Root
                    .ElementsNoNamespace("WizardData")
                    .ElementsNoNamespace("packages")
                    .ElementsNoNamespace("package")
                    .Select(e => e.Attribute("id").Value)
                    .ToList();
            }
        }
    
        public void ProjectFinishedGenerating(Project project)
        {
            var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
            var _installer = componentModel.GetService();
    
            foreach (var package in _packages) {
                _installer.InstallLatestPackage(null, project, package, false, false);
            }
        }
    }
    

    And then use following in vstemplate:

      
        MyProjectWizard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=22c2a1a5fa7b6905
        MyProjectWizard.MyProjectWizard
      
    

提交回复
热议问题