是否有 NANT 任务来启动/停止 COM+成分?

发布于 2024-12-06 22:27:57 字数 92 浏览 0 评论 0原文

我正在使用 CC.net 和 NANT 构建脚本自动化我们的部署网络。我必须在部署期间停止并启动 COM+ 组件。

是否有 NANT 任务可以执行此操作?

I am automating our deploymnet using CC.net and a NANT build script. I have to stop and start our COM+ components during deployment.

Is there a NANT task that does this?

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

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

发布评论

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

评论(2

心欲静而疯不止 2024-12-13 22:27:57

假设 COM+ 组件是您的组件 (ServicedComponent实例),那么您可以使用 任务 来实现此目的。

您必须指示 COM+ 组件所在的程序集,删除应用程序(使用带有 ActionType of uninstall),然后再次安装(为此您可能需要两个任务实例)。

如果您的程序集不是 COM+ 组件/应用程序的源,那么您将需要编写自己的自定义任务来访问 COM+ 管理 API 通过 COM 互操作。

Assuming that the COM+ components are your components (ServicedComponent instances), then you can use the <regsvcs> task to achieve this.

You would have to indicate the assembly that your COM+ components are in, remove the application (using an action with an ActionType of uninstall) and then install it again (you might need two task instances for this).

If your assembly is not the source of the COM+ components/application, then you will need to write your own custom task accessing the COM+ Administration API through COM interop.

浅笑轻吟梦一曲 2024-12-13 22:27:57

我一直在为同样的问题而苦苦挣扎。除了vbs脚本之外找不到其他详细的方法。我提出的解决方案如下:

我创建了一个引用 NAnt.Core 的 C# .Net 解决方案。我创建了两个继承自 Nant Task 类的类(任务)。你需要三件事:
1) 将 TaskName 属性放在类上

     [TaskName("startupComApplicationTask")]

2) 将 Task 属性放在您想要从 Nant 传入的任何属性上

    [TaskAttribute("machineName", Required = true)]

3) 实现 ExecuteTask() 方法

最终结果如下所示:

[TaskName("startupComApplicationTask")]
public class StartupComApplicationTask: Task
{
    private string _applicationName;
    private string _machineName;

    [TaskAttribute("applicationName", Required = true)]
    public string ApplicationName
    {
        get
        {
            return _applicationName;
        }
        set
        {
            _applicationName = value;
        }
    }

    [TaskAttribute("machineName", Required = true)]
    public string MachineName
    {
        get
        {
            return _machineName;
        }
        set
        {
            _machineName = value;
        }
    }

    protected override void ExecuteTask()
    {
        COMAdminCatalog objAdmin = new COMAdminCatalog();
        objAdmin.Connect(MachineName);

        var objCollection = (COMAdminCatalogCollection)objAdmin.GetCollection("Applications");

        objCollection.Populate();

        foreach (COMAdminCatalogObject objAppNames in objCollection)
        {
            if (objAppNames.Name.Equals(ApplicationName))
            {
                ICatalogCollection objComponents = (ICatalogCollection)objCollection.GetCollection("Components", objAppNames.Key);
                objComponents.Populate();
            }
        }

        objAdmin.StartApplication(ApplicationName);
    }
}

显然,为了实现这一点,您需要包括对 ComAdmin 互操作程序集的引用。您可以在 Com 参考资料中的“COM+ 1.0 类型库”下找到它。

构建将为您创建两个 dll 的项目。互操作性和你的。将它们放入您的 nant 文件夹(在 bin 目录中)。

您可以通过以下方式从 Nant 内部调用这些:

    <startupComApplicationTask machineName="193.132.119.249" applicationName="NantTest" />

重复关闭操作,只需调用 ShutdownApplication 而不是 StartApplication。

希望这有帮助

I've been struggling with the same problem. Couldn't find any other detailed way than vbs scripts. The solution I came up with is as follows:

I created a C# .Net solution which references NAnt.Core. I created two classes (tasks) which inherit from the Nant Task class. You need three things:
1) Place TaskName attribute on the class

     [TaskName("startupComApplicationTask")]

2) Place a Task attribute on any properties that you want to pass in from Nant

    [TaskAttribute("machineName", Required = true)]

3) Implement the ExecuteTask() Method

The Final outcome was something like this:

[TaskName("startupComApplicationTask")]
public class StartupComApplicationTask: Task
{
    private string _applicationName;
    private string _machineName;

    [TaskAttribute("applicationName", Required = true)]
    public string ApplicationName
    {
        get
        {
            return _applicationName;
        }
        set
        {
            _applicationName = value;
        }
    }

    [TaskAttribute("machineName", Required = true)]
    public string MachineName
    {
        get
        {
            return _machineName;
        }
        set
        {
            _machineName = value;
        }
    }

    protected override void ExecuteTask()
    {
        COMAdminCatalog objAdmin = new COMAdminCatalog();
        objAdmin.Connect(MachineName);

        var objCollection = (COMAdminCatalogCollection)objAdmin.GetCollection("Applications");

        objCollection.Populate();

        foreach (COMAdminCatalogObject objAppNames in objCollection)
        {
            if (objAppNames.Name.Equals(ApplicationName))
            {
                ICatalogCollection objComponents = (ICatalogCollection)objCollection.GetCollection("Components", objAppNames.Key);
                objComponents.Populate();
            }
        }

        objAdmin.StartApplication(ApplicationName);
    }
}

Obviously in order to get this going you need to include a reference to the ComAdmin interop assembly. Which you can find under "COM+ 1.0 Type Library" in your Com references.

Build the project which will create two dlls for you. The interop one and yours. Drop these into your nant folder (in the bin directory).

You can call these from within Nant the following way:

    <startupComApplicationTask machineName="193.132.119.249" applicationName="NantTest" />

Repeat for shutingdown, just call ShutdownApplication instead of StartApplication.

Hope this helps

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