Eric Deslauriers wrote:
The docs could use a tad more detail: http://nant.sourceforge.net/help/tasks/exec.html
Fortunately, this came to my aid. http://www.mail-archive.com/nant-users@lists.sourceforge.net/msg05320.ht ml
This is an OK solution for a limited # of execs, or a set of execs I can
kick of via foreach, but if I have to change variables between calls,
and the calls aren't ordered the same or aren't the same, it makes for
some long, repetitive sections. And since properties are immutable, I
don't think I can create the limited sets of <call>, set some values,
and make the calls?
what makes you think properties are immutable ?
well if its sneaky/devious you're after - the original link you posted is on the right track. Heres a slightly cleaner version using a custom task:Any sneaky/devious folk out there want to wade in (offlist is OK too)? :)
----------------------------------------------------------------------------------------------------------------------------------------------------------------
<script language="C#" >
<imports>
<import namespace="System.Runtime.InteropServices"/>
</imports>
<code><![CDATA[ [DllImport("kernel32.dll", SetLastError=true)]
static extern bool SetEnvironmentVariable(string lpName, string lpValue);
[TaskName("setenv")]
public class SetEnvTask : Task {
private string _name;
private string _value;
[TaskAttribute("name", Required=true)]
public string EnvName {
get { return _name; }
set { _name = value; }
}
[TaskAttribute("value", Required=true)]
public string EnvValue {
get { return _value; }
set { _value = value; }
}
protected override void ExecuteTask() {
Log(Level.Info, "Setting env var {0} to {1}", EnvName, EnvValue );
if ( ! SetEnvironmentVariable(EnvName, EnvValue) ) {
throw new BuildException(string.Format("Error setting env var {0} to {1}", EnvName, EnvValue ) , Location);
} } }
]]></code>
</script>
<!-- echo current value if it exists --> <if test="${environment::variable-exists('X')}" >
<echo message="X = ${environment::get-variable('X')}" />
</if>
<echo message="Setting new value"/> <setenv name="X" value="test"/>
<echo message="X = ${environment::get-variable('X')}" />
----------------------------------------------------------------------------------------------------------------------------------------------------------------
This way you don't have to call a specific target - just use the custom <setenv> task. And its simple to set variables between calls to other tasks.
The above generates the following output: Target(s) specified: build
[script] Scanning assembly "00f_4pst" for extensions. [echo] Setting new value [setenv] Setting env var X to test [echo] X = test
build:
This is probably somthing worth considering adding to NAnt. Of course we would need to use platform #ifdefs as the above is windows specific.
Ian
Eric D
-----Original Message-----[mailto:[EMAIL PROTECTED]
From: Castro, Edwin Gabriel (Firing Systems Engr.)
environmentSent: Wednesday, December 08, 2004 12:55 PM To: Merrill Cornish; Eric Deslauriers; NAnt Users mailing list Subject: RE: [Nant-users] Creating/setting env variables
.NET can, on the other hand, start a process with particular
variables set. The <exec> task has an <environment> element for this
purpose. I use it to call devenv.exe and set the appropriate PATH,
INCLUDE, and LIB environment variable for that execution only.
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/
_______________________________________________
Nant-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-users
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/
_______________________________________________
Nant-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-users