如何在设计时解决装配问题?

发布于 2024-08-08 22:51:49 字数 552 浏览 3 评论 0原文

我有一个可扩展性库(或一个库的开始),带有 UITypeEditor。我现在想用 EditorAttribute 来装饰该属性。我不想引用可扩展性库,因为它不需要部署,所以我使用这个:

[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/debug 文件夹)。是否有一些特殊的地方可以放置可扩展性 dll,以便 .net 可以解析程序集?

谢谢!

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; }

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?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

晚风撩人 2024-08-15 22:51:49

只需输入 Regedit.exe 并创建一个密钥,如下所示:

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

密钥的名称是什么并不重要,Visual Studio 会在设计时搜索 AssemblyFoldersEx 中列出的所有文件夹名称以查找程序集。

必须使用以文件夹路径作为值的(默认)条目在 Regedit 中添加文件夹。 (例如,请参见同级键)。

有趣的是,当您在 .NET 选项卡上的项目上下文菜单上单击“添加新引用”时,AssemblyFoldersEx 注册表项中存在的所有文件夹也会自动出现。

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

我刚刚进行了以下测试: 在资源程序集上,我放置了以下代码:

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 窗体可执行程序集)上一个从 Button 派生的组件,就像这样:

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

两个程序集之间没有引用。一切都很好。

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

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

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).

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.

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;
    }
}

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.

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