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

发布于 2024-09-14 07:30:34 字数 293 浏览 0 评论 0原文

我们已经用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我也只是我 2024-09-21 07:30:34

我过去曾不得不解决这个问题。在一种情况下,它是安装到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文