nant脚本c#编译错误

发布于 2024-11-10 07:34:42 字数 3962 浏览 2 评论 0原文

不幸的是,我对 NANT 知识的了解非常有限,但今天开始更新我们的构建以运行一些代码。我们使用巡航控制。

这工作正常 - 但是我需要处理两个文件夹,因此尝试将通用代码放入传统的 C# 方法中。

<echo message="Ensure only 4 directories in the backup directory"/>
    <script language="C#">
      <code>
        <![CDATA[
  public static void ScriptMain(Project project)
  {
      string path = project.Properties["build.ReleasesShareLocation.BackupParent"];
      string [] folders = System.IO.Directory.GetDirectories(path,"*", System.IO.SearchOption.TopDirectoryOnly);

      System.Collections.ArrayList dirlist = new System.Collections.ArrayList();
      foreach (string folder in folders)
      {
          dirlist.Add(new System.IO.DirectoryInfo(folder));
      }
      dirlist.Sort(new DirectoryInfoDateComparer());
      dirlist.Reverse();

      for (int i = 4; i < dirlist.Count; i++)
      {
          string foldername = ((System.IO.DirectoryInfo)dirlist[i]).Name;
          try
          {
              ((System.IO.DirectoryInfo)dirlist[i]).Delete(true);
              project.Log(Level.Info, String.Format("Deleted folder {0}", foldername));

          }
          catch { project.Log(Level.Warning, String.Format("Unable to delete folder {0}", foldername)); }
      }
  }

    internal class DirectoryInfoDateComparer : System.Collections.IComparer
    {
        public int Compare(object x, object y)
        {
            System.IO.DirectoryInfo di1 = (System.IO.DirectoryInfo)x;
            System.IO.DirectoryInfo di2 = (System.IO.DirectoryInfo)y;

            return di1.CreationTime.CompareTo(di2.CreationTime);
        }
    }
    ]]>
      </code>
    </script>

我没有重复所有代码 - 我尝试添加一个静态类,其中包含一个方法来完成所有处理,以便 main 只传递两个路径。但是在服务器上运行构建时(有没有办法让我在本地“编译”这个?)它出错了。

这是出错的代码 - 我不确定我是否错过了一个简单的语法错误(我确实尝试在 Visual Studio 中复制并粘贴代码以确保括号和内容匹配)或者是否有不同的我需要在 NANT 构建中执行此操作。

<echo message="Ensure only 4 directories in the backup directory"/>
    <script language="C#">
      <code>
        <![CDATA[
  public static void ScriptMain(Project project)
  {
      string path = project.Properties["build.ReleasesShareLocation.BackupParent"];
      string path2 = project.Properties["build.DeltaScriptFileShareLocation.BackupParent"];
      Processor.ProcessFolder(path);
      Processor.ProcessFolder(path2);
  }

internal static class Processor
{
    public static void ProcessFolder(string path)
    {
        string [] folders = System.IO.Directory.GetDirectories(path,"*", System.IO.SearchOption.TopDirectoryOnly);

        System.Collections.ArrayList dirlist = new System.Collections.ArrayList();
        foreach (string folder in folders)
        {
            dirlist.Add(new System.IO.DirectoryInfo(folder));
        }
        dirlist.Sort(new DirectoryInfoDateComparer());
        dirlist.Reverse();

        for (int i = 4; i < dirlist.Count; i++)
        {
            string foldername = ((System.IO.DirectoryInfo)dirlist[i]).Name;
            try
            {
                ((System.IO.DirectoryInfo)dirlist[i]).Delete(true);
                project.Log(Level.Info, String.Format("Deleted folder {0}", foldername));

            }
            catch { project.Log(Level.Warning, String.Format("Unable to delete folder {0}", foldername)); }
        }
    }
}

    internal class DirectoryInfoDateComparer : System.Collections.IComparer
    {
        public int Compare(object x, object y)
        {
            System.IO.DirectoryInfo di1 = (System.IO.DirectoryInfo)x;
            System.IO.DirectoryInfo di2 = (System.IO.DirectoryInfo)y;

            return di1.CreationTime.CompareTo(di2.CreationTime);
        }
    }
    ]]>
      </code>
    </script>

感谢您的帮助:)


编辑:

我返回了 CC 日志并重新阅读了错误消息 - 这次了解了它试图告诉我的内容。结果我需要将项目参数传递给我的新方法。 :)

有没有一种方法可以编译代码而不必运行构建来查找这样的错误?我尝试将其粘贴到 Visual Studio 中,但由于我没有引用 Nant 库,因此它无法有效地突出显示错误。或者是否可以在开发计算机上下载并安装一些东西来引用适当的 dll?

Unfortunately my knowledge of NANT stuff is very limited but embarked today on updating our build to run some code. We use cruisecontrol.

This works fine - however I need to process two folders so was trying to put common code into a traditional c# method.

<echo message="Ensure only 4 directories in the backup directory"/>
    <script language="C#">
      <code>
        <![CDATA[
  public static void ScriptMain(Project project)
  {
      string path = project.Properties["build.ReleasesShareLocation.BackupParent"];
      string [] folders = System.IO.Directory.GetDirectories(path,"*", System.IO.SearchOption.TopDirectoryOnly);

      System.Collections.ArrayList dirlist = new System.Collections.ArrayList();
      foreach (string folder in folders)
      {
          dirlist.Add(new System.IO.DirectoryInfo(folder));
      }
      dirlist.Sort(new DirectoryInfoDateComparer());
      dirlist.Reverse();

      for (int i = 4; i < dirlist.Count; i++)
      {
          string foldername = ((System.IO.DirectoryInfo)dirlist[i]).Name;
          try
          {
              ((System.IO.DirectoryInfo)dirlist[i]).Delete(true);
              project.Log(Level.Info, String.Format("Deleted folder {0}", foldername));

          }
          catch { project.Log(Level.Warning, String.Format("Unable to delete folder {0}", foldername)); }
      }
  }

    internal class DirectoryInfoDateComparer : System.Collections.IComparer
    {
        public int Compare(object x, object y)
        {
            System.IO.DirectoryInfo di1 = (System.IO.DirectoryInfo)x;
            System.IO.DirectoryInfo di2 = (System.IO.DirectoryInfo)y;

            return di1.CreationTime.CompareTo(di2.CreationTime);
        }
    }
    ]]>
      </code>
    </script>

Rather than repeat all the code - I tried to add a static class with a method to do all the processing so that the main only passes the two paths. But in running the build on the server (is there a way for me to "compile" this locally??) it errored.

This is the code that errored - I'm not sure if I've missed a simple syntax error (I did try to copy and paste the code in visual studio to make sure the brackets and stuff matched up) or if there is a different way I need to do it in NANT build..

<echo message="Ensure only 4 directories in the backup directory"/>
    <script language="C#">
      <code>
        <![CDATA[
  public static void ScriptMain(Project project)
  {
      string path = project.Properties["build.ReleasesShareLocation.BackupParent"];
      string path2 = project.Properties["build.DeltaScriptFileShareLocation.BackupParent"];
      Processor.ProcessFolder(path);
      Processor.ProcessFolder(path2);
  }

internal static class Processor
{
    public static void ProcessFolder(string path)
    {
        string [] folders = System.IO.Directory.GetDirectories(path,"*", System.IO.SearchOption.TopDirectoryOnly);

        System.Collections.ArrayList dirlist = new System.Collections.ArrayList();
        foreach (string folder in folders)
        {
            dirlist.Add(new System.IO.DirectoryInfo(folder));
        }
        dirlist.Sort(new DirectoryInfoDateComparer());
        dirlist.Reverse();

        for (int i = 4; i < dirlist.Count; i++)
        {
            string foldername = ((System.IO.DirectoryInfo)dirlist[i]).Name;
            try
            {
                ((System.IO.DirectoryInfo)dirlist[i]).Delete(true);
                project.Log(Level.Info, String.Format("Deleted folder {0}", foldername));

            }
            catch { project.Log(Level.Warning, String.Format("Unable to delete folder {0}", foldername)); }
        }
    }
}

    internal class DirectoryInfoDateComparer : System.Collections.IComparer
    {
        public int Compare(object x, object y)
        {
            System.IO.DirectoryInfo di1 = (System.IO.DirectoryInfo)x;
            System.IO.DirectoryInfo di2 = (System.IO.DirectoryInfo)y;

            return di1.CreationTime.CompareTo(di2.CreationTime);
        }
    }
    ]]>
      </code>
    </script>

Thanks for any assistance :)


Edit:

I went back through the CC logs and re-read the error message - this time understanding what it was trying to tell me. Turns out I needed to pass my new method the Project parameter. :)

Is there a way to be able to compile the code without having to run a build to find errors like this? I tried pasting it into Visual Studio but as I didn't have the Nant library referenced it wasn't highlighting the error effectively. Or is there something you can download and install on a dev machine to reference appropriate dlls?

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

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

发布评论

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

评论(2

何处潇湘 2024-11-17 07:34:42

转到命令提示符,导航到安装 NANT 的文件夹,然后手动键入 NANT 构建命令,例如:

 nant -f:MyBuildFile.build

这样您就会看到错误,我们可以提供进一步帮助。

Go to command prompt, navigate to the folder where you installed NANT, and type in your NANT build command manually, for example:

 nant -f:MyBuildFile.build

That way you'll see the errors, and we can help further.

失眠症患者 2024-11-17 07:34:42

在重新阅读错误日志时,我在红色文本墙内找到了答案。

结果我需要将项目参数传递给我的新方法(因为我指的是项目属性)。

那么问题就解决了!

In re-reading the error logs I found within the wall of red text the answer.

Turns out I needed to pass my new method the Project parameter (as I was referring to Project properties).

So problem solved!

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