0

I'm trying to install a nuget package into a project that I am generating with a VSPackage. So far, I am able to create a solution from a project template:

Solution4 soln = (Solution4)ApplicationObject.Solution;

string prjPath = "C:\\MyProject";
string templatePath = soln.GetProjectTemplate(@"SomeProject\MyTemplate.vstemplate", "CSharp");

soln.AddFromTemplate(templatePath, prjPath, "New CSharp Project", false);

But now I need to be able to install a nuget package into that project as well. The package is located online, for example, https://somewhere.mydomain.com/nuget/feed , and has the ID PackageX.

Drake
  • 2,679
  • 4
  • 45
  • 88

1 Answers1

1

You'll need to perform the same steps that "NuGet Package Restore" does, adding NuGet.exe, NuGet.config and NuGet.targets correctly to the solution. To see how this changes things, diff two empty solutions where one restores NuGet packages and the other doesn't.

To add your custom feed, you can add

  <packageSources>
    <add key="local" value="https://somwhere.mydomain.com/nuget/feed"/>
  </packageSources>

to NuGet.config under the <configuration> node.

Finally, add the package name and version to packages.config in the vcproj directory and you should be all set!

Ani
  • 10,826
  • 3
  • 27
  • 46