Misha,

To access a property that has been set in your build file using c#,
try 

<property name="my.property" value="my.property.value"/>

And in c# 

string property = project.Properties[ "my.property" ];

This will set property to the value of my.property. 


Also look at the example included with nant called script-sample.build: 

<script language="C#" mainclass="Test" logprefix= "script">
   <code><![CDATA[

      class Test {
        public static void ScriptMain(Project project) {

                        PropertyDictionary pd = project.Properties;
                  foreach (DictionaryEntry property in pd) {
                  Console.WriteLine("{0} = {1}", property.Key,
property.Value);
                  }

                  Console.WriteLine("Setting test.property to 'new
value'");
                  pd["test.property"] = "new value";
                }
            }

            ]]></code>
        </script>


David


Message: 1
Date: Tue, 8 Jun 2004 13:10:42 -0400
From: "Misha Rybalov" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Subject: [Nant-users] How do you pass properties from NAnt to C#?

This is a multi-part message in MIME format.

------_=_NextPart_001_01C44D7B.87BF0318
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I've been using Ant for years and have always used the following way to
=
pass properties from my build.xml files to my Java programs:=20

<sysproperty key=3D"my.property" value=3D"${my.property}" />

In Java, I can access this property by:=20

System.getProperty("my.property");


I want to do the exact same thing but using NAnt and C#. I've tried =
doing this in NAnt:


        <property name=3D"sys.env.my.property"
value=3D"my.property.value"/>

        <sysinfo verbose=3D"true"/>

And then this in C#:


Environment.GetEnvironmentVariable("sys.env.my.property"); //doesn't =
work


Environment.GetEnvironmentVariable("my.property"); //doesn't work either


How can you access properties that are set in a build file, from a C# =
program?


Thanks for any help.

Misha




-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
>From Windows to Linux, servers to mobile, InstallShield X is the
one installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
Nant-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to