2

Is there any instructions to add nugets and references in project template?

The best way is to add nuget without version. Nugets will be added not from nuget.org but from internal corporate resource.

What I mean. In the SolutionExplorer picture red boxes are references from nugets and blue boxes are references were included using Add reference.

Solution Explorer

After I used Export template I don't see any references in zip folder.

zip folder

And when I create new project with my template I see errors on nuget references and no errors on references from PC(but their absolute pathes are not in the project so I can't distribute template to other developers).

Solution explorer

Bradley Uffner
  • 16,641
  • 3
  • 39
  • 76

2 Answers2

0

Regarding nugets, use package manager console and add (for eg: Install-Package Newtonsoft.Json) and then click enter.

For the references, according to the image, it may refer to the GAC and not the local bin folder of the solution. The best way is always to maintain the references in the Bin/Reference folder and then refer from it.

In this case, you need to import the dll again.

Hope it helps!

Palle Due
  • 5,929
  • 4
  • 17
  • 32
Ruban J
  • 622
  • 1
  • 7
  • 31
  • Thank you for your answer! But I mean that question: **how to create template with nuggets and references so when some1 creates new project using it he won't get any errors and all references will work?** – Vladislav Vitalyev May 17 '16 at 12:33
  • You can create a solution with all the nuggets added. For references, first add all the dll's to a reference folder included in the solution and from the folder, add the reference to the project. Now you are good to go. – Ruban J May 17 '16 at 12:38
  • Thanks. I understand what to do with references but not sure about nugets. You say `Regarding nuggets, use package manager console and add (for eg: Install-Package Newtonsoft.Json) and then click enter.` But I want that Nuget is got from repository automatically while creating new project. I thought it should be some strings in .vstemplate file. – Vladislav Vitalyev May 17 '16 at 13:05
  • Refer my previous comment. When you add a solution(not project) and add the nugget, even when it is compressed, it will be available since that is with the solution. – Ruban J May 17 '16 at 13:08
  • It can go wrong, e.g. (1) when older references don't point to available NuGet versions or (2) when your reference points to dll organised outside Packages, e.g. in \Binaries.The subdir will not be included in the template zip and exclamation mark will appear when unpacked. I had an issue using an older template for a component that uses Antlr.Runtime. I first remove the dependency on /Binaries in cproj, Then I had to replace the package version by a newer version, 3.1.1.. When I exported the template using this existing NuGet reference, it all worked. – Goodies Aug 11 '17 at 13:54
0

Specific instructions for creating a project template with nuget packagaes are documented at nuget.org. Unfortunately, it is not possible to add a nuget package to a project template without a version number:

The wizard supports multiple elements. Both the id and version attributes are required. An important consequence of this is that a specific version of a package will be installed even if a newer version is available in the online package feed.

The reason for this behavior is that a future version of a package might introduce a change that is not compatible with the project/item template. The choice to upgrade the package to the latest version using NuGet is left to the developer who is in the best position to assume the risks of upgrading the package to the latest version.

vstemplate (this is required to invoke package download at template inflation):

<WizardExtension>
    <Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
    <FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
</WizardExtension>

package list:

<WizardData>
    <packages>
        <package id="jQuery" version="1.6.2" />
    </packages>
</WizardData>

There are additional options documented on the nuget site linked above, such as creating a VSIX template.

Bradley Uffner
  • 16,641
  • 3
  • 39
  • 76