未经创建自定义活动设计到设计中的DLL的Windows Workflow Foundation [英] Creating custom activity design without reference to Design DLL in Windows Workflow Foundation

查看:287
本文介绍了未经创建自定义活动设计到设计中的DLL的Windows Workflow Foundation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的的Windows Workflow Foundation 自定义活动,然后我想在我的工作流创建自定义设计作为这些活动。


>我能够使设计项目,设计XAML。另外,我能看到的定制设计,他们在工作流程中,如果我直接引用我的工作流项目的设计项目



这是什么,我不喜欢做的事,因为设计师DLL不应该被部署到生产环境。我只想在Visual Studio中的工作流编辑器定制设计



我能够得到的东西,加入以下工作:

  [设计师(命名空间,DLL)] 
公共类CustomActivity:NativeActivity的<串GT;

和这个复制的DLL到Visual Studio的路径之后。这使该dll被复制一些固定的Visual Studio路径不是很好又是什么,我不喜欢做的事,因为每一个开发者都应该做到这一点,使构建。



我用这两个例子,但似乎这两个直接引用的DLL:





我将承担这种功能会以某种方式通过在Visual Studio / Workflow Foundation的支持。



你有什么想法如何解决这个问题?谢谢!


解决方案

设计师属性(用神奇的字符串)是不是很可靠。如果你改变你的类名或命名空间,你会不会有一个编译错误。
还有另一个(更好恕我直言)的方式用做 IRegisterMetadata 实施




  1. 您的设计组件必须引用您的活动组装,但是这通常是无法避免的。

  2. 添加部分类(的.cs)添加到您XAML设计

  3. 这个类必须从 System.Activities.Presentation.Metadata.IRegisterMetadata 继承。这个接口只定义一个方法来实现



下面是一个实现示例:

 公共无效寄存器()
{
AttributeTableBuilder建设者=新AttributeTableBuilder();
builder.AddCustomAttributes(
typeof运算(MyActivity),
新DesignerAttribute(typeof运算(MyActivityDesigner)));
MetadataStore.AddAttributeTable(builder.CreateTable());
}



接下来,你想在Visual Studio中使用的自定义设计。 Visual Studio中有严格的规定,以自动加载设计组件。您需要:




  1. 您的设计项目必须有比你的活动项目相同的名称,以。设计末增加。例如:

    • Activiy项目:MyApp.Activities.dll

    • Designer项目:MyApp.Activities.Design.dll


  2. 的。设计DLL必须在同一个目录比活性DLL。您可以在设计项目后生成事件自动完成这个



重要编辑:



我现在看到您的链接已经存在这种方法,但你说,它直接引用的DLL。是的,设计dll引用该活动的dll。
,而你问的正好相反:活动DLL不应引用设计DLL。
使用IRegisterMetadata方法,你的设计的DLL可以参考该活动的dll,这不是一个问题:您可以从发布包中取出了设计的dll,活动DLL将正常工作


I am using Windows Workflow Foundation with custom Activities, and I would like to create custom Design for these activities in my workflow.

I am able to make the design project, and the designer xaml. Also I am able to see the custom design for them in the workflow, if I directly refer the Design project in my Workflow project.

This is something that I would not like to do, because the Designer DLL should not be deployed to production environment. I would only like to have the custom design in Visual Studio workflow editor.

I was able to get things working by adding following:

[Designer("namespace,dll")]
public class CustomActivity : NativeActivity<string>

and after this copying the dll to visual studio path. This is again something that I would not like to do, because every developer should do this and making the build so that the dll is copied some fixed visual studio path is not very good.

I used these two examples, but it seems that both of these directly refer the DLL:

I would assume this kind of feature would somehow be supported by the Visual Studio/Workflow Foundation.

Do you have any ideas how to resolve this? Thanks!

解决方案

The Designer attribute (using "magic" string) is not something very reliable. If you change your class name or namespace, you'll not have a compilation error. There is another (better imho) way to do it using IRegisterMetadata implementation:

  1. Your Design assembly must reference your activity assembly, but this usually can't be avoided.
  2. Add a partial class (.cs) to your XAML designer
  3. This class must inherit from System.Activities.Presentation.Metadata.IRegisterMetadata. this interface only define one method to implement.

Here is a implementation sample:

public void Register()
{
    AttributeTableBuilder builder = new AttributeTableBuilder();
    builder.AddCustomAttributes(
        typeof(MyActivity),
        new DesignerAttribute(typeof(MyActivityDesigner)));
    MetadataStore.AddAttributeTable(builder.CreateTable());
}

Next, you'll want to have the custom designer used in Visual Studio. Visual Studio have strict rules to automatically load designer assemblies. You need:

  1. Your designer project must have the same name than your activity project, with ".Design" added at the end. Example:
    • Activiy project: MyApp.Activities.dll
    • Designer project: MyApp.Activities.Design.dll
  2. The .Design dll must be in the same directory than the activity dll. You can automate this with a post build event in the designer project.

Important Edit:

I see now that your links already present this method but you say that it directly reference the DLL. Yes, the DESIGN dll reference the ACTIVITY dll. But you asked the opposite: the activity dll shouldn't reference the design dll. Using the IRegisterMetadata method, your DESIGN dll can reference the ACTIVITY dll, it's not a problem: you can remove the design dll from the released package, the activity dll will work fine.

这篇关于未经创建自定义活动设计到设计中的DLL的Windows Workflow Foundation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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