Bugs item #1947694, was opened at 2008-04-21 12:57
Message generated for change (Comment added) made by dammar
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=402868&aid=1947694&group_id=31650

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Tasks
Group: 0.86
Status: Closed
Resolution: Fixed
Priority: 5
Private: No
Submitted By: Michael Kusmiy (dammar)
Assigned to: Gert Driesen (drieseng)
Summary: C# XML parsing code with RegEx fails running on NAnt 0.86.29

Initial Comment:
C# XML parsing code with RegEx fails running on NAnt 0.86.2962.0

I installed the NAnt 0.86 (Build 0.86.2962.0; nightly; 10.02.2008) because bug 
1859708 was fixed there. After that following C# code crashes while runs OK on 
NAnt-0.85 and NAnt-0.86-beta1. 

        <property name="BuildNumber" value="2.0.0.0" />
        <property name="BuildDate" 
value="${string::substring(datetime::to-string(datetime::now()), 0, 
2)}-${string::substring(datetime::to-string(datetime::now()), 3, 
2)}-${string::substring(datetime::to-string(datetime::now()), 6, 4)}"/>

        <property name="filepath" value="c:\projects\GlobalAssemblyInfo.cs"/>
        <property name="filevss" value="${vssprojects}/GlobalAssemblyInfo.cs"/>
        
     <script language="C#">
<imports>
        <import namespace="System.Xml"></import> 
        <import namespace="System.Xml.XPath"></import> 
</imports>
        <code><![CDATA[
     public static void ScriptMain(Project project)
     {
          string fileVersion = Path.Combine(project.BaseDirectory, 
project.Properties["filepath"]);
      StreamReader reader = new StreamReader(project.Properties["filepath"]);
      string contents = reader.ReadToEnd();
      reader.Close();

      string replacement = string.Format(
       "[assembly: AssemblyVersion(\"{0}\")]", 
project.Properties["BuildNumber"]);
      string replacement2 = string.Format(
       "[assembly: AssemblyFileVersion(\"{0}\")]", 
project.Properties["BuildNumber"]);
      string replacement3 = string.Format(
       "[assembly: AssemblyInformationalVersion(\"{0}\")]", 
project.Properties["BuildDate"]);
      string newText = Regex.Replace(contents, @"\[assembly\s*: 
AssemblyVersion\("".*""\)\]", replacement);
      string newText2 = Regex.Replace(newText, @"\[assembly\s*: 
AssemblyFileVersion\("".*""\)\]", replacement2);
      string newText3 = Regex.Replace(newText2, @"\[assembly\s*: 
AssemblyInformationalVersion\("".*""\)\]", replacement3);

      StreamWriter writer = new StreamWriter(fileVersion, false);
      writer.Write(newText3);
      writer.Close();
     }
     ]]>
     </code>
    </script>


The code execution fails with the same errors on both machines with .Net SDK 
and without it. Errors are as follows:

error CS0234: The type or namespace name 'Xml' does not exist in the namespace 
'System' (are you missing an assembly reference?)

If  <imports> … </imports> is omitted, nAnt returns following error (builds ok 
on previous nAnt releases):
error CS0103: The name 'Regex' does not exist in the current context

Thanks for grate product, but please fix this issue or specify a workaround.


----------------------------------------------------------------------

>Comment By: Michael Kusmiy (dammar)
Date: 2008-04-21 15:48

Message:
Logged In: YES 
user_id=2068495
Originator: YES

Thank you. However it takes even more than that -
System.Text.RegularExpressions needs to be referenced, and it is in
System.dll - not in mscorlib.dll as I thought. The final working code looks
like this:

<script language="C#">
  <references>
        <include name="System.dll" />
        <include name="System.Xml.dll" />
  </references>
  <imports>
    <import namespace="System.Text.RegularExpressions" />
    <import namespace="System.Xml" />
    <import namespace="System.Xml.XPath" />
  </imports>
  ...
</script>

Thanks for your time and assistance. Too bad that writing c# sripts for
nAnt will be even harder now for beginners :(

Regards.


----------------------------------------------------------------------

Comment By: Gert Driesen (drieseng)
Date: 2008-04-21 15:01

Message:
Logged In: YES 
user_id=707851
Originator: NO

Michael,

You also need to import the System.Text.RegularExpressions namespace:

<script language="C#">
  <references>
    <include name="System.Xml.dll" />
  </references>
  <imports>
    <import namespace="System.Text.RegularExpressions" />
    <import namespace="System.Xml" />
    <import namespace="System.Xml.XPath" />
  </imports>
  ...
</script>

That info is also in the release notes.

----------------------------------------------------------------------

Comment By: Michael Kusmiy (dammar)
Date: 2008-04-21 14:35

Message:
Logged In: YES 
user_id=2068495
Originator: YES

Thanks for your comments but it does not resolve the issue - instead I get
this error:
error CS0103: The name 'Regex' does not exist in the current context

I tried it on environments with .Net 2.0 SDK installed and without it,
referencing dll from GAC or on file system, but with the same result:
  <references>    <include name="System.Xml.dll" />  </references>
or
<references>
        <include
name="c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.XML.dll" />
</references>

However the script runs OK on NAnt-0.86-beta1 regardels do I specify
reference and import and how (GAC or file system).

Thanks for your time.

----------------------------------------------------------------------

Comment By: Gert Driesen (drieseng)
Date: 2008-04-21 13:51

Message:
Logged In: YES 
user_id=707851
Originator: NO

Michael,

You need to add a reference to the System.Xml assembly:

<script language="C#">
  <references>
    <include name="System.Xml.dll" />
  </references>
  <imports>
    <import namespace="System.Xml"></import> 
    <import namespace="System.Xml.XPath"></import> 
  </imports>
  ...
</script>

This breaking change is documented in the release notes:
http://nant.sourceforge.net/nightly/latest/releasenotes.html

Depending on the feedback that I get for this change, I might still revert
it before the final release of NAnt 0.86.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=402868&aid=1947694&group_id=31650

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
nant-developers mailing list
nant-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-developers

Reply via email to