2

我正在使用带有自定义活动的Windows Workflow Foundation,并且我想在我的工作流中为这些活动创建自定义设计。

我能够制作设计项目和设计师 xaml。如果我直接在我的工作流程项目中引用设计项目,我也可以在工作流程中看到他们的定制设计。

这是我不想做的事情,因为不应将 Designer DLL 部署到生产环境。我只想在 Visual Studio 工作流编辑器中进行自定义设计。

通过添加以下内容,我能够使事情正常进行:

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

然后将 dll 复制到 Visual Studio 路径。这又是我不想做的事情,因为每个开发人员都应该这样做并且进行构建以便复制 dll 一些固定的 Visual Studio 路径不是很好。

我使用了这两个示例,但似乎这两个都直接引用了 DLL:

我会假设 Visual Studio/Workflow Foundation 会以某种方式支持这种功能。

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

4

1 回答 1

0

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.

于 2014-02-28T16:06:26.383 回答