在项目模板中包含对自己的程序集的引用的最佳方法是什么? [英] What is the best way to include references to my own assemblies in a project template?

查看:85
本文介绍了在项目模板中包含对自己的程序集的引用的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经使用C#开发了一个库,现在我希望创建一个项目模板来帮助正确使用该库.

We have developed a library in C#, and now I wish to create a project template to aid in using the library correctly.

我希望新项目包含对库程序集的引用,但希望不必将程序集部署到GAC,也不必依赖位于某个特定位置的程序集.

I want new projects to include a reference to the library assembly, but would prefer not to have to deploy the assembly to the GAC, or to depend on the assembly residing in some specific location.

我在想将.dll包含在项目模板.zip文件中.这意味着它将结束于新项目的项目文件夹中的某个位置.也许在一个名为Lib的文件夹中.然后,项目文件中的参考提示可以指向该文件夹.这是一个好主意吗?我可能会遇到什么问题?

What I am thinking is to include the .dll in the project template .zip file. That means it will end up somewhere inside the project folder of new projects. Perhaps in a folder named Lib. Then the reference hint in the project file can point to that folder. Is that a good idea? What problems might I face down the road?

是否存在某种我不知道的在项目模板中包含此类第三方库的机制?您如何解决这个问题?当然我不是第一个.

Is there perhaps some mechanism for including such 3rd party libraries in project templates that I'm not aware of? How have you tackled this? Surely I'm not the first.

推荐答案

我过去不得不解决此问题.在一种情况下,它是安装到GAC的日志记录库,这意味着Reference元素仅需要程序集名称.在另一种情况下,我们将库安装到文件系统,创建了包含该位置的注册表项(以防用户变得可爱并更改了我们的安装位置),并使用了

I have had to address this issue in the past. In one case, it was a logging library that was installed to the GAC, which meant the Reference element simply needed the assembly name. In another case, we installed the library to the file system, created a registry key that contained the location (in case the user got cute and changed the install location on us) and used a project template wizard to look up the registry key and populate a replacement item to have the correct location in the Reference's HintPath. (Note: the template wizard approach requires you to install your wizard's assembly to the GAC, which it sounds like you're trying to avoid...)

如果您不希望将库安装在GAC或特定位置,则将程序集包括在项目中的方法几乎是您唯一的选择.从正面看,您的项目模板的部署非常简单,您不必费心使用GAC,自定义向导等.从负面看,如果您创建了库的新修订版,则用户将需要更新每个项目的库副本.

If you don't want your library to be installed in either the GAC or a specific location, the approach of including the assembly in the project is pretty much your only remaining option. On the positive side, deployment of your project template is fairly straightforward and you don't have to muck with the GAC, custom wizards, etc. On the negative side, if you ever create a new revision of your library, your users will need to update every project's copy of the library.

这篇关于在项目模板中包含对自己的程序集的引用的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆