在设计时如何解决组件? [英] How is an assembly resolved at design time?

查看:127
本文介绍了在设计时如何解决组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可扩展库(或一个开始),用UITypeEditor的。我现在想装饰与EditorAttribute财产。我不想引用扩展库,因为它并不需要部署,所以我用这样的:

I have an extensibility library (or the start of one), with a UITypeEditor. I'd now like to decorate the property with the EditorAttribute. I don't want to reference the extensibility library, as it does not need to be deployed, so I'm using this:

[Editor("MyProject.Extensibility.MyUIEditor, MyProject.Extensibility, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", typeof (UITypeEditor))]
MySpecialType SpecialType { get; set; }

这是行不通的。该类型编辑器是对枚举使用,当我用这个,标准枚举下拉所示。但是,如果您复制型编辑到项目,并使用直下式的参考,一切运作良好。我试着使用Activator.CreateInstance测试我的字符串,我已经得到了工作。该MyProject.Extensibility.dll被复制到几乎每一个地方(所有项目的bin /调试文件夹)。有一些把一个可扩展DLL,以便.NET能够解决装配特殊的地方?

This doesn't work. The type editor is for use on enums and when I use this, the standard enum drop down is shown. However, if you copy the type editor into the project and use a direct type reference, all works well. I've tried testing my string using Activator.CreateInstance and I've got that to work. The MyProject.Extensibility.dll is copied into just about every where (all the project's bin/debug folders). Is there some special place to put an extensibility dll so .net can resolve the assembly?

谢谢!

推荐答案

只需输入regedit.exe,然后创建一个密钥就像:

Just enter Regedit.exe and create a key just like:


HKLM\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\AssemblyFoldersEx\StackOverflow

这其实并不重要,关键的名称,在AssemblyFoldersEx列出的所有文件夹名称搜索的内容由Visual Studio组件设计时。

It doesn't really matter what the name of the key is, all folder names listed within AssemblyFoldersEx are searched for Assemblies design-time by Visual Studio.

一个文件夹必须在注册表编辑器使用具有价值的文件夹路径(默认)项中添加。 (参见同级例如键)。

A folder must be added in Regedit using a (Default) entry having the folder path as value. (See sibling keys for example).

有趣的是,当您点击添加新引用在一个项目范围内目前在AssemblyFoldersEx注册表项中的所有文件夹会自动还会出现。.NET选项卡上的菜单

It's interesting that all folders present in the AssemblyFoldersEx registry key will automatically also appear when you click "Add New Reference" on a project context menu on the .NET tab.

另一种方法是到所需的程序集添加到全局访问缓存(C:\Windows\Assembly)

Another approach would be to add the desired assembly to Global Access Cache (c:\Windows\Assembly)

我只是做了如下测试:在资源程序集,我把下面的代码:

I just made the following test: On a resource assembly I put the following code:

public class MyEditor : UITypeEditor
{
    public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
    {
        return UITypeEditorEditStyle.Modal;
    }

    public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
    {
        MessageBox.Show("Works");
        return null;
    }
}

在消费者组件(Windows窗体可执行程序集)我创建从按钮派生就像这样一个组成部分:

On the consumer assembly (Windows forms executable assembly) I created a component that derives from Button just like this:

public class MyButton : Button
{
    [Editor("AssemblyReferenceCL.MyEditor, AssemblyReferenceCL", typeof(UITypeEditor))]
    public String MyProp { get; set; }
}



有两个组件之间没有提及。一切工作就好了。

There's no reference between the two assemblies. Everything worked just fine.

这篇关于在设计时如何解决组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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