简体   繁体   English

在Windows Workflow Foundation中创建自定义活动设计而不参考Design DLL

[英]Creating custom activity design without reference to Design DLL in Windows Workflow Foundation

I am using Windows Workflow Foundation with custom Activities , and I would like to create custom Design for these activities in my workflow. 我正在将Windows Workflow Foundation自定义活动一起使用 ,并且我想在我的工作流中为这些活动创建自定义设计

I am able to make the design project, and the designer xaml. 我可以进行设计项目,也可以进行设计师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 . 如果我直接在Workflow项目中引用Design项目那么我也可以在工作流中看到针对他们的自定义设计。

This is something that I would not like to do, because the Designer DLL should not be deployed to production environment. 这是我不希望做的事情,因为不应将Designer DLL部署到生产环境中。 I would only like to have the custom design in Visual Studio workflow editor. 我只想在Visual Studio工作流编辑器中进行自定义设计。

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. 然后将dll复制到visual studio路径。 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. 这又是我不希望做的事情,因为每个开发人员都应该这样做并进行构建,以便将dll复制到某个固定的Visual Studio路径中不是很好。

I used these two examples, but it seems that both of these directly refer the DLL: 我使用了这两个示例,但是似乎这两个示例都直接引用了DLL:

I would assume this kind of feature would somehow be supported by the Visual Studio/Workflow Foundation. 我认为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. Designer属性(使用“魔术”字符串)不是很可靠。 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: 使用IRegisterMetadata实现还有另一种(更好的恕我直言)方法:

  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 将局部类(.cs)添加到XAML设计器
  3. This class must inherit from System.Activities.Presentation.Metadata.IRegisterMetadata . 此类必须从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中使用自定义设计器。 Visual Studio have strict rules to automatically load designer assemblies. Visual Studio具有严格的规则来自动加载设计器程序集。 You need: 你需要:

  1. Your designer project must have the same name than your activity project, with ".Design" added at the end. 设计器项目的名称必须与活动项目的名称相同,并在末尾添加“ .Design”。 Example: 例:
    • Activiy project: MyApp.Activities.dll 活动项目:MyApp.Activities.dll
    • Designer project: MyApp.Activities.Design.dll 设计器项目:MyApp.Activities.Design.dll
  2. The .Design dll must be in the same directory than the activity dll. .Design dll必须与活动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. 我现在看到您的链接已经显示了此方法,但是您说它直接引用了DLL。 Yes, the DESIGN dll reference the ACTIVITY dll. 是的,DESIGN DLL引用了ACTIVITY DLL。 But you asked the opposite: the activity dll shouldn't reference the design dll. 但是您却提出了相反的要求:活动dll不应引用设计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. 使用IRegisterMetadata方法,您的DESIGN dll可以引用ACTIVITY dll,这不是问题:您可以从已发布的程序包中删除设计dll,活动dll可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows Workflow Foundation-在工作流中的不同活动之间传递自定义变量 - windows Workflow foundation - passing custom variable between different activity in a workflow Windows Workflow Foundation 3在并行活动中等待 - Windows Workflow Foundation 3 wait inside parallel activity 设计自定义 Windows 窗体 - Design Custom Windows Forms 在Design View中使用DLL引用加载UserControl时出现问题 - Problem loading UserControl with DLL reference in Design View 如何对Windows Workflow Foundation(WF)活动可以序列化进行单元测试? - How to unit test that a Windows Workflow Foundation (WF) activity can be serialized? Windows Workflow Foundation每隔X分钟重复一次活动 - Windows Workflow Foundation Repeat an Activity Every X minutes Windows Workflow Foundation 4.5接收活动队列行为 - Windows Workflow Foundation 4.5 Receive Activity Queuing Behavior Windows Workflow Foundation NullReferenceException - Windows Workflow Foundation NullReferenceException 将图像添加到Windows工作流自定义活动设计器 - Add an image to a windows workflow custom activity designer CRM:在 C# 中创建工作流和工作流自定义活动的区别 - CRM: Difference between creating Workflow and Workflow custom activity in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM