在项目模板中包含对自己的程序集的引用的最佳方法是什么?

编程入门 行业动态 更新时间:2024-10-28 04:30:28
本文介绍了在项目模板中包含对自己的程序集的引用的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们已经使用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元素仅需要程序集名称.在另一种情况下,我们将库安装到文件系统,创建了包含该位置的注册表项(以防用户变得可爱并更改了我们的安装位置),并使用了项目模板向导以查找注册表项并填充替换项以在其中具有正确的位置参考的提示路径. (注意:模板向导方法要求您将向导的程序集安装到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...)

如果您不希望将库安装在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.

更多推荐

在项目模板中包含对自己的程序集的引用的最佳方法是什么?

本文发布于:2023-11-08 11:50:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569294.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   对自己的   程序   方法   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!