whatever - I was just seeing if I could reproduce what that script was doing in a function.Please, don't do this kind of tricks. It is like shooting yourself in the foot. Functions (by definition) should be side-effect-free and nobody is advised to do otherwise.
I'm not so sure that we should disable it. I think saying that functions should be side-effect free is a useful guideline but does not need to be cast in stone. If its easier in some cases to define a small function that happens to set a couple of properties as well then I don't see a reason to explicitly disable the ability.I was just going to propose a patch that would prevent ANY writes to property dictionary during property evaluation, just to prevent this kind of abuse.
To be sure all the custom functions that we ship with nant should be side-effect free but if I feel like writing a wacky function in a script block in *my* build file that does all sort of stuff to the project object I'd rather not have that ability taken away from me.
insistence on lack of side effects is the reason that variables in xslt are immutable and IMHO is more hindrance than help.
Ian
BTW. I think that because version info is a complex structure, a task would be more conventient here:
<get-assembly-version assembly="aaa.dll" propertyprefix="xxx" />
This would set the following properties:
xxx.minorversion xxx.majorversion xxx.buildversion xxx.privateversion xxx.author ... xxx.copyright
Jarek
----- Original Message ----- From: "Ian MacLean" <[EMAIL PROTECTED]>
To: "Ian MacLean" <[EMAIL PROTECTED]>
Cc: "Price, Henry" <[EMAIL PROTECTED]>; "'Bob Archer'"
<[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Friday, April 30, 2004 6:50 PM
Subject: Re: [Nant-users] get version from dll?
actually you can set the properties from the function as well. Like:
<script language="C#" prefix="script" > <code><![CDATA[
[Function("get-file-version")] public string GetFileVersion( string file, bool setProperties ) {
System.Diagnostics.FileVersionInfo myFileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(file); if ( setProperties ) { Project.Properties["dll.majorversion"] = myFileVersionInfo.FileMajorPart.ToString(); Project.Properties["dll.minorversion"] = myFileVersionInfo.FileMinorPart.ToString(); Project.Properties["dll.buildversion"] = myFileVersionInfo.FileBuildPart.ToString(); Project.Properties["dll.privateversion"] = myFileVersionInfo.FilePrivatePart.ToString(); } return myFileVersionInfo.FileVersion;
}
]]></code> </script>
the advantage of a custom function over a block of script in a target is that you only have to define it once and can then call it for each file you need version info for.
Ian
Ian MacLean wrote:
This is nice. Better than my assembly specific version.
Note that if you are using a current nightly you can wrap your diagnostics code in a custom function definition like:
<code><![CDATA[ [Function("get-file-version")] public string GetFileVersion( string file ) { System.Diagnostics.FileVersionInfo myFileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(file); return myFileVersionInfo.FileVersion; } ]]></code> </script> and then call it like:
<property name="fileversion" value="script::get-file-version('somefile.dll')" />
of course if you need to set properties to the individual version components then a custom task is a better option.
Bob, You should be able to drop the above code into your build file if all you need is the file version as a string.
Ian
Price, Henry wrote:
How about something like this? (off the top of my head and without intellisense :)
We've done something similar here - for checking which versions of files are installed etc - had to do it all in script - I've given up on writing custom tasks, they take too long to edit when you need to change stuff :)
<script language="C#"> <code><![CDATA[ public static void ScriptMain(Project project) { System.Diagnostics.FileVersionInfo myFileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo("path to your dll"); project.Properties["dll.majorversion"] = myFileVersionInfo.FileMajorPart; project.Properties["dll.minorversion"] = myFileVersionInfo.FileMinorPart; project.Properties["dll.buildversion"] = myFileVersionInfo.FileBuildPart; project.Properties["dll.privateversion"] = myFileVersionInfo.FilePrivatePart; ]]></code> </script>
-----Original Message----- From: Bob Archer [mailto:[EMAIL PROTECTED] Sent: 30 April 2004 4:21P To: [EMAIL PROTECTED] Subject: [Nant-users] get version from dll?
Hi All,
I am creating a build script that deploys our last successful daily build to our QA machine.
How could I get the version/build number from a dll? Any ideas? I could get the last build number from the build number file that my version task uses, however, if that build failed it will not be the one in the daily build area.
Thanks,
Bob
"This communication is intended solely for the addressee and is confidential and not for third party unauthorised distribution."
-- Ian MacLean, Developer, ActiveState, a division of Sophos http://www.ActiveState.com
------------------------------------------------------- This SF.Net email is sponsored by: Oracle 10g Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE. http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click _______________________________________________ Nant-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/nant-users
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Nant-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-users
--
Ian MacLean, Developer, ActiveState, a division of Sophos
http://www.ActiveState.com
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Nant-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-users