Visual Studio 项目模板和私有程序集引用
我注意到其他人之前问过类似的(如果不完全相同的话)问题,但它的答案没有帮助(无论如何,我)。
我有一个项目,我正在从中构建模板。当我在程序文件中引用程序集时,模板项目本身可以正常构建,但基于它构建的任何项目都找不到引用的程序集。我尝试直接编辑csproj,但这也不起作用。我如何引用这样的非 GACed DLL?我是否被迫使用 IWizard 技巧?
I noticed someone else asked a similar, if not exactly the same, question before, but the answer to it didn't help (me, anyway).
I have a project that I'm building a template from. When I go to reference an assembly in the Program Files, the template project itself will build fine, but any projects built off of it cannot find the referenced assembly. I tried editing the csproj directly, but that didn't work either. How do I reference non-GACed DLLs like that? Am I forced to use an IWizard trick?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的。您可以通过以下方式执行此操作:
a) 在硬盘驱动器上的相应文件夹中引用您的私有程序集,例如它们将被安装的位置
b) 将项目导出为模板
c) 解压模板的新 zip 文件
d) 打开 .vstemplate 文件
e) 在 TemplateContent 节点的底部,添加一个 References 节点,并为每个引用添加一个 Reference 节点作为 References 的子级,然后添加一个 Assembly 节点作为其子级,并带有程序集的名称。如果程序集位于 GAC 中,我相信您需要输入完全限定的程序集名称,但否则,它似乎仅适用于程序集名称。
最初,我设置了一个应该搜索的环境路径变量;然而,它最终是不必要的,因为基于模板构建的项目在路径中没有它的情况下也可以正常工作。
Okay. You can do this by:
a) Reference your private assemblies in the appropriate folder on the hard-drive, e.g. where they're going to be installed
b) Export the project as a template
c) Extract the new zip file of the template
d) Open the .vstemplate file
e) At the bottom of the TemplateContent node, add a References node, and for each reference, add a Reference node as a child of References, then an Assembly node as a child of that, with the name of the assembly. If the assembly is in the GAC, I believe you need to put the fully-qualified assembly name, but otherwise, it seems to work with just the assembly name.
Originally, I'd set an environment path variable that should be searched; however, it ended up being unnecessary, as projects built on the template worked fine without it in the path.
对于 Web 项目,我发现处理此问题的最佳方法是将 Bin 文件夹包含到项目中,并在该文件夹中包含所有私有程序集。关键是要包含 Bin 文件夹,否则该文件夹将无法复制。
For Web Projects the best way I've found to handle this is to Include the Bin folder into the project with all the private assemblies in that folder. It's key that the Bin folder is included or else the folder won't copy.
我终于在 VS 2010 中找到了一种简单的方法,所以我包含了这个答案,因为它很难找到。
在vs2010中
转到项目,
然后打包/发布设置,
然后“资源”选项卡,
单击添加资源,
找到要包含的程序集文件。
完毕!
I finally found an easy way in VS 2010 so I am including this answer as it was so hard to find.
in vs2010
Go to Project,
then Package/Publish Settings,
then Resources tab,
Click on Add Resource,
locate the assembly file to include.
Done!