在项目模板中包含对我自己的程序集的引用的最佳方法是什么?
我们已经用 C# 开发了一个库,现在我希望创建一个项目模板来帮助正确使用该库。
我希望新项目包含对库程序集的引用,但不希望必须将程序集部署到 GAC,或者依赖于驻留在某个特定位置的程序集。
我的想法是将 .dll 包含在项目模板 .zip 文件中。这意味着它将最终出现在新项目的项目文件夹中的某个位置。也许在名为 Lib 的文件夹中。然后项目文件中的引用提示就可以指向该文件夹。这是个好主意吗?我以后可能会遇到什么问题?
是否有某种机制可以将此类第三方库包含在我不知道的项目模板中?你是如何解决这个问题的?当然我不是第一个。
We have developed a library in C#, and now I wish to create a project template to aid in using the library correctly.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我过去曾不得不解决这个问题。在一种情况下,它是安装到 GAC 的日志库,这意味着 Reference 元素只需要程序集名称。在另一种情况下,我们将库安装到文件系统,创建一个包含该位置的注册表项(以防用户变得可爱并更改我们的安装位置)并使用 项目模板向导查找注册表项并填充替换项以使其具有正确的位置参考文献的提示路径。 (注意:模板向导方法要求您将向导的程序集安装到 GAC,这听起来像是您试图避免的...)
如果您不希望将库安装在 GAC 或特定的库中位置,将程序集包含在项目中的方法几乎是您唯一剩下的选择。从积极的一面来看,项目模板的部署相当简单,您不必与 GAC、自定义向导等搞混。从消极的一面来看,如果您创建了库的新版本,您的用户将需要更新每个项目的库副本。
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...)
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.