C# DLL 删除 Interop 和 AxInterop 文件
我正在 C# 中开发一个 DLL,它在 GUI 中以及代码端使用外部 C++ DLL COM 组件。我总共使用了 3 个其他组件,对于我引用的每个组件,我都会在输出中获得一个“Interop.ComponentName.dll”文件。
我确实尝试将“属性”窗口中的“复制本地”设置更改为 false,但在运行时出现主 DLL 找不到文件的错误。
我知道程序运行需要这些文件,但是是否可以在子目录中使用这些文件,例如主 dll 位于“”../extras/Test.dll”中,我希望 Interop 文件位于“../extras/Test.dll”中。 ./extras/TestResources/"?
额外信息:我在 Windows XP SP3 中使用 C# 和 Visual Studio 2008。
谢谢,K。
I'm developing a DLL in C# that uses external C++ DLL COM-Components in the GUI and also for the code side. In total I am using 3 other components and for each one I reference I get a "Interop.ComponentName.dll" file included in the output.
I did try to change the setting "Copy Local" in the "Properties" window to false but I get errors at runtime that the main DLL cannot find the files.
I understand that these are needed for the program to function but is it possible to use these files in a subdirectory such as the main dll is in ""../extras/Test.dll" and I would like the Interop files in "../extras/TestResources/"?
Extra Info: I'm using C# with Visual Studio 2008 in Windows XP SP3.
Thanks, K.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您引用了哪些互操作 DLL?如果它们是非标准的(即未包含在您的目标 .NET 框架发行版中),则 Visual Studio 可能会将它们包含在您的项目输出中,因为它们未在全局程序集缓存中注册。
考虑分布式 C# 应用程序如何引用外部 DLL。如果它们是 .NET 发行版的一部分,那么它们会在用户的 GAC 中正确注册。否则,您的设置/部署项目将注册它们。如果是后者,那么如果您转到原始项目的属性,在“构建”下,您应该会看到输出路径字段。 Visual Studio 的内部构建实用程序仅允许您将项目的构建文件输出到单个目录。
但是,有一种方法可以实现您的要求。不过,这比允许 Visual Studio 处理您的部署要复杂得多。查看 MSBuild.exe 和构建脚本。
Which interop DLLs are you referencing? If they're non-standard (i.e. not included in your targeted .NET framework distribution), then Visual Studio may include them in your project output as they're not registered in your Global Assembly Cache.
Consider how your distributed C# application would reference external DLLs. If they're part of the .NET distribution, then they're properly registered in the user's GAC. Otherwise, your setup/deployment project would register them. If it's the latter, then if you go to your original project's properties, under Build, you should see the output path field. Visual Studio's internal build utility will only allow you to output your project's build files to a single directory.
However, there IS a way to achieve what you're asking. It's quite a bit more complicated than allowing Visual Studio to handle your deployment though. Take a look into MSBuild.exe and build scripts.
要使 CLR 能够查找不在 bin 文件夹或它自动搜索的其他位置中的程序集,您可以使用app.config 文件中的元素。
请参阅 http://msdn.microsoft.com/en- us/library/efs781xb(vs.71).aspx 了解如何执行此操作的详细信息。
链接文章中有 2 行需要注意:
如果程序集是私有程序集,则代码库设置必须是相对于应用程序目录的路径。
对于没有强名称的程序集,版本将被忽略,加载程序将使用的第一次出现。在内部
To enable the CLR to find assemblies that are not in your bin folder or the other locations it automatically searches, you can use the <codeBase> element in your app.config file.
See http://msdn.microsoft.com/en-us/library/efs781xb(vs.71).aspx for details on how to do this.
2 lines for you to note from the linked article:
If the assembly is a private assembly, the codebase setting must be a path relative to the application's directory.
For assemblies without a strong name, version is ignored and the loader uses the first appearance of <codebase> inside <dependentAssembly>