【问题标题】:nant task to create queue with c# code使用 C# 代码创建队列的 nant 任务
【发布时间】:2009-10-27 11:00:48
【问题描述】:
<project name="aa" default="createqueue" xmlns="http://nant.sf.net/release/0.85/nant.xsd">
<target name="createqueue">
<echo message="started" />
    <script language="C#" >
            <references>
                <lib>
                    <include name="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Messaging.dll" />
                </lib>
            </references>
            <imports>
                  <import namespace="System" />
                  <import namespace="System.Messaging" />
            </imports>
            <code>
                <![CDATA[
                public static void ScriptMain(Project project)
                    {
                        string queueName = @".\Public$\TicketMatchingService";
                        if (!MessageQueue.Exists(queueName))
                        {
                            MessageQueue.Create(queueName, true);
                        }
                    }
                ]]>
            </code>
    </script>
    <echo message="ended" />
</target>
</project>

我收到以下错误消息

C:\queuetask.build(4,3):
Compilation failed:
c:\Documents and Settings\refundspair1\Local Settings\Temp\pnf11egc.0.cs(17,14) : error CS0234: The type or namespace name 'Messaging' does not exist in the namespace 'System' (are you missing an assembly reference?)
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.3603
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using NAnt.Core;
using NAnt.Core.Attributes;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Messaging;
using System.Text;
using System.Text.RegularExpressions;



[FunctionSet("script", "script")]
public class nant0aac150cbd424d3c93af8adc13adf050 : NAnt.Core.FunctionSetBase {


    public static void ScriptMain(Project project)
     {
      string queueName = @".\Public$\TicketMatchingService";
      if (!MessageQueue.Exists(queueName))
      {
       MessageQueue.Create(queueName, true);
      }
     }


    public nant0aac150cbd424d3c93af8adc13adf050(NAnt.Core.Project project, NAnt.Core.PropertyDictionary propDict) :
            base(project, propDict) {
    }
}

Total time: 0.3 seconds.

【问题讨论】:

    标签: c# nant compilation task


    【解决方案1】:

    尝试以下方法:

    <project name="aa" default="createqueue" xmlns="http://nant.sf.net/release/0.85/nant.xsd">
        <target name="createqueue">
            <echo message="started" />
            <script language="C#" >
                <references>
                        <include name="System.Messaging.dll" />
                </references>
                <imports>
                    <import namespace="System" />
                    <import namespace="System.Messaging" />
                </imports>
                <code>
                    <![CDATA[
                        public static void ScriptMain(Project project)
                        {
                        string queueName = @".\Public$\TicketMatchingService";
                        if (!MessageQueue.Exists(queueName))
                        {
                        MessageQueue.Create(queueName, true);
                        }
                        }
                    ]]>
                </code>
            </script>
            <echo message="ended" />
        </target>
    </project>
    

    我能够使用版本 nant 0.85.248.0 成功编译它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多