What I have been doing is conditionally running a script task that tries
to discover those user settings and saves them in a UserSettings.xml
file. The script only runs if the UserSettings.xml file doesn't exist
allowing developers to configure the file to their liking.
This example is using the function idea that I proposed to only execute
if a file exists so it won't work on the public version of nant. But
the idea is this:
* Have the buildfile create the settings file that nant can include
directly if it doesn't exist.
* Include the settings file to get the properties that developers are
expected to change.
Now all your environment variables are explictly stated and located in
one location.
<script language="C#" unless="${FileExists('UserSettings.xml')}">
<code><![CDATA[
// create the UserSettings.xml file by looking at the system
this is being run on
// and save the results to the file for future use.
public static void ScriptMain(Project project) {
string userSettingsPath = "UserSettings.xml";
string visualStudioPath = "";
// get install directory from registry
//
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\6.0\Setup\Microsoft
Visual C++
Microsoft.Win32.RegistryKey installKey =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Vi
sualStudio\6.0\Setup\Microsoft Visual C++");
if (installKey != null) {
string productDir = (string)
installKey.GetValue("ProductDir");
if (productDir != null) {
// visual studio root is one directory up from
product directory
visualStudioPath =
Directory.GetParent(productDir).FullName;
}
} else {
throw new BuildException("Visual C++ not installed
on this computer.");
}
// create user settings file to store user specific
package information
try {
System.Xml.XmlTextWriter writer = new
System.Xml.XmlTextWriter(userSettingsPath, System.Text.Encoding.ASCII);
writer.WriteStartDocument();
writer.Formatting = System.Xml.Formatting.Indented;
writer.WriteComment(" Delete this file to have this
package recreate it from your environment. ");
writer.WriteStartElement("project");
writer.WriteStartElement("property");
writer.WriteAttributeString("name",
"package.VisualStudio.appdir");
writer.WriteAttributeString("value",
visualStudioPath);
writer.WriteEndElement();
writer.Close();
} catch (Exception e) {
string msg = String.Format("Could not create user
settings file '{0}'.", userSettingsPath);
throw new BuildException(msg, e);
}
}
]]></code>
</script>
<include buildfile="UserSettings.xml"/>
<echo message="use a property defined in user settings"/>
-----Original Message-----
From: Kevin Dente [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 10, 2002 4:04 PM
To: Smith, Eric V.; [EMAIL PROTECTED]
Subject: RE: [nant-dev] patch to support resolving properties from
environment vars
I actually think that "configurable properties" -
properties whose values are defined externally from
the build files - would be a useful capability. I
believe it's something that has been discussed in the
past, although I don't think it ever got out of the
discussion phase.
An XML configuration file would be a more natural
place than the environment to define such property
values, in my opinion. But the idea is the same. I
like to keep our build files somewhat static. That is,
if the path to an application changes, or I'm building
into a separate build root, I don't want to have to
change the build files. Of course, you can get a
similar feature by <include>ing a changeable build
file.
Even without generically configurable properties, what
I would really like to see is a way to dynamically
specify paths to executables for
ExternalProgramBase-derived tasks. Requiring things to
be in the search path is a less than ideal solutions.
--- "Smith, Eric V." <[EMAIL PROTECTED]> wrote:
> I think it would cause problems. I never want to
> specify settings in
> the environment. I want everything to be in the
> .build file. With this
> patch, the environment would be silently used,
> without my knowledge.
>
> I think you're better off having a task that sets a
> property from the
> environment. That way the usage of environment
> variables is explicit.
>
> -----Original Message-----
> From: Cort Schaefer [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 10, 2002 6:15 PM
> To: '[EMAIL PROTECTED]'
> Subject: RE: [nant-dev] patch to support resolving properties
> from environment vars
>
>
>
> This would be great and would allow for individual
customizations per
> a developers environment.
>
>
>
> -----Original Message-----
> From: Ben Lowery [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 10, 2002 3:27 PM
> To: [EMAIL PROTECTED]
> Subject: [nant-dev] patch to support resolving
> properties from
> environment vars
>
> don't know if people consider this worthwhile or
> not, but i find
> it very
> handy when dealing with projects broken down into
> multiple
> buildfiles. the
> patch allows nant to attempt to resolve properties
> not in the
> PropertyDictionary from the Environment. So, if
> you have a
> property called
> "build.dir" but it's not set in your project, but
> is set in your
>
> environment, the property will be pulling in from
> the
> environment.
>
> here's the revised indexer, against
> /src/NAnt.Core/PropertyDictionary.cs
>
> public virtual string this[string name] {
> get {
> string value = (string) Dictionary[(object)
> name];
> if(null == value) {
> //try to resolve from environment
> value =
> System.Environment.GetEnvironmentVariable(name);
> if(null!=value)
> value =
>
>
ExpandProperties(System.Environment.ExpandEnvironmentVariables(value));
>
> }
> return value;
> }
> set {
> if (!_readOnlyProperties.Contains(name)) {
> Dictionary[name] = value;
> }
> }
> }
>
> --b
>
>
>
>
>
-------------------------------------------------------
>
> This sf.net email is sponsored by: OSDN - Tired of
> that same old
>
> cell phone? Get a new here for FREE!
>
>
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
>
> _______________________________________________
> Nant-developers mailing list
> [EMAIL PROTECTED]
>
>
https://lists.sourceforge.net/lists/listinfo/nant-developers
>
>
>
__________________________________________________
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute
-------------------------------------------------------
In remembrance
www.osdn.com/911/ _______________________________________________
Nant-developers mailing list [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-developers
-------------------------------------------------------
In remembrance
www.osdn.com/911/
_______________________________________________
Nant-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-developers