VSIX with Project Templates and NuGet Packages

核能气质少年 提交于 2019-11-27 23:16:15

I've made a step by step video on how to make a VSIX that auto downloads nuget packages.

http://www.youtube.com/watch?v=_ZvsFz41H-E

Since there are many steps and I never wrote them down, I won't type them here. I've definitely tested my VSIX package on other people's machine and it worked so hopefully this will work for you.

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

public class MyProjectWizard : IWizard
{
    IEnumerable<string> _packages;

    public void RunStarted(object automationObject, Dictionary<string, string> 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<IVsPackageInstaller2>();

        foreach (var package in _packages) {
            _installer.InstallLatestPackage(null, project, package, false, false);
        }
    }
}

And then use following in vstemplate:

  <WizardExtension>
    <Assembly>MyProjectWizard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=22c2a1a5fa7b6905</Assembly>
    <FullClassName>MyProjectWizard.MyProjectWizard</FullClassName>
  </WizardExtension>
user2624591

Check out this link http://samritchie.net/2012/09/17/nuget-packages-in-vs2012-templates/ which helped me. However, I'm still running into the issue where all my references' paths are empty.

Note especially the following comment from the article linked above:

I spent a considerable period of time attempting to work out what the v2 equivalent of CustomExtension was, but to cut a long story short, you don’t need to make any changes to the .vsixmanifest — it’s enough to include all of the packages in the VSIX under a ‘Packages’ directory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!