How to add references and nugets in visual studio project template?

旧城冷巷雨未停 提交于 2019-12-24 01:54:57

问题


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.

After I used Export template I don't see any references in 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).


回答1:


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.




回答2:


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!



来源:https://stackoverflow.com/questions/37275619/how-to-add-references-and-nugets-in-visual-studio-project-template

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