您能否强制 MonoTouch 在其静态编译中包含未引用的程序集? [英] Can you force MonoTouch to include an unreferenced assembly in its static compilation?

查看:26
本文介绍了您能否强制 MonoTouch 在其静态编译中包含未引用的程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MonoTouch 应用程序,它在运行时动态实例化一个类(使用 Type.GetType()).该类位于应用程序中其他任何地方都没有引用的程序集中,因此 MonoTouch 静态编译器认为未使用该程序集并在编译应用程序时忽略该程序集.如果我在应用程序中添加对类的引用,则编译器包含程序集并且对 Type.GetType() 的调用工作正常:

I have a MonoTouch app that dynamically instantiates a class (using Type.GetType()) at runtime. The class is in an assembly that is not referenced anywhere else in the app, so the MonoTouch static compiler thinks that the assembly isn't used and ignores the assembly when it compiles the app. If I add a reference to the class in the app, then the compiler includes the assembly and the call to Type.GetType() works fine:

MyAssembly a;

我更愿意告诉编译器在编译应用程序时始终包含项目参考"中列出的所有程序集.这可能吗?

I would prefer to just tell the compiler to always include all the assemblies listed in the project's "References" when it compiles the app. Is this possible?

谢谢,-汤姆 B.

推荐答案

你能解决这个问题吗?如果没有,我有一个类似的问题:有没有办法强制 MonoDevelop 构建/加载程序集?

Were you able to figure this out yet? If not, I had a similar problem: Is there a way to force MonoDevelop to build/load an assembly?

据我所知,这就是 C# 编译器的工作方式.我能够通过添加一个自定义的预构建步骤来解决这个问题,该步骤将一个类脚本化到引用程序集中,其中包括对未引用程序集的虚拟引用,如下所示:

As I understand it, that's just how the C# compiler works. I was able to get around this by adding a custom pre-build step that scripts a class into the referencing assembly that includes dummy references to the unreferenced assemblies, like so:

using System;

namespace MyNamespace
{
    public static class Referencer
    {
        Type t;

        //These lines are scripted one per class in the unreferenced assemblies
        //You should only need one per assembly, but I don't think more hurts.
        t = typeof(Namespace1.Class1);
        t = typeof(Namespace2.Class2);
        ...
        t = typeof(NamespaceN.ClassN);
    }
}

这篇关于您能否强制 MonoTouch 在其静态编译中包含未引用的程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆