nant script

Xml code posted by RuWi
created at 14 Feb 20:49

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<project default="help">
    <property name="solution"                           unless="${property::exists('solution')}"                            value="ProjectX.sln" />    
    <property name="configuration"                      unless="${property::exists('configuration')}"                       value="Debug"        />    
    <property name="CCNetListenerFile"                  unless="${property::exists('CCNetListenerFile')}"                   value="listen.xml"    />    
    <property name="msbuildverbose"                     unless="${property::exists('msbuildverbose')}"                      value="normal"       />    
    <property name="CCNetLabel"                         unless="${property::exists('CCNetLabel')}"                          value="0.0.0.0"      />     

    <property overwrite="false" name="msbuildlogger"    value="C:\Program Files\CruiseControl.NET\server\MSBuildListener.dll"                     />
    <property overwrite="false" name="versionInfofile"  value="VersionInfo.cs" />

    <!-- custom scripts --> 
     <script language="C#" prefix="RuWi">
          <references>
              <include name="System.Xml.dll" />
              <include name="System.dll" />
          </references>
          <imports>
              <import namespace="System.Text" />
          </imports>
          <code>
            <![CDATA[
                [Function("UpdateVersionFile")]
                public static bool UpdateVersionFile(string inputFile, string newVersion, bool debugMode)
                {
                    bool ok = true;
                    try
                    {
                        System.IO.StreamReader versionFile = new System.IO.StreamReader(inputFile, System.Text.Encoding.ASCII);
                        string line = "";
                        System.Text.StringBuilder result = new StringBuilder();
                        string searchPatternVersion = @"(\d+\.\d+\.\d+\.\d+)";
                        string searchPatternAssemblyProduct = string.Format(@"AssemblyProduct\({0}(.*?)\{0}", "\"");
                        string replacePatternAssemblyProduct = string.Format(@"AssemblyProduct({0}(Debug)${1}1{2}{0}", "\"", "{", "}");

                        while (!versionFile.EndOfStream)
                        {
                            line = versionFile.ReadLine();

                            if (System.Text.RegularExpressions.Regex.IsMatch(line, searchPatternVersion) && (line.Contains("AssemblyFileVersion")))
                            {
                                line = System.Text.RegularExpressions.Regex.Replace(line, searchPatternVersion, newVersion);
                            }

                            if (debugMode && System.Text.RegularExpressions.Regex.IsMatch(line, searchPatternAssemblyProduct))
                            {
                                line = System.Text.RegularExpressions.Regex.Replace(line, searchPatternAssemblyProduct, replacePatternAssemblyProduct);
                            }

                            result.AppendLine(line);
                        }

                        versionFile.Close();

                        System.IO.StreamWriter updatedVersionfile = new System.IO.StreamWriter(inputFile);
                        updatedVersionfile.Write(result.ToString());
                        updatedVersionfile.Close();
                    }
                    catch (Exception ex)
                    {
                        ok = false;
                        Console.WriteLine(ex.ToString());
                    }
                    return ok;
                }
                ]]>
          </code>
     </script>
    <!-- end custom scripts --> 


    <target name="help" >   
        <echo message="Removed for keeping the file shorter." />
    </target>
    
    <target name="clean" description="deletes all created files">
        <delete >
            <fileset>
                <patternset >
                    <include name="**/bin/**"  />
                    <include name="**/obj/**"  />
                </patternset>
            </fileset>
        </delete>
    </target>
    
    <target name="adjustversion" description="Adjusts the version in the version.info file">
        <if test="${not file::exists(versionInfofile)}">
            <fail message="file: ${versionInfofile}  which must contains the version info was NOT found" />
        </if>

        <echo message="Setting version to ${CCNetLabel}" />        
       
        <property name="debugMode" value = "False" />
        <property name="debugMode" value = "True"  if="${configuration=='Debug'}"  />
        <if test="${not RuWi::UpdateVersionFile(versionInfofile,CCNetLabel,debugMode)}">
            <fail message="updating file: ${versionInfofile}  which must contains the version info failed" />
        </if>
    </target>
    
    <target name="compile" description="compiles the solution in the wanted configuration" depends="adjustversion">                         
        <msbuild  project="${solution}" >
            <arg value="/p:Configuration=${configuration}" />
            <arg value="/p:CCNetListenerFile=${CCNetListenerFile}" />
            <arg value="/v:${msbuildverbose}" />
            <arg value="/l:${msbuildlogger}" /> 
        </msbuild>
    </target>
            
</project>    
5.32 KB in 6 ms with coderay