How about this?

Assembly ass = Assembly.GetExecutingAssembly();
FileVersionInfo versionInfo =
FileVersionInfo.GetVersionInfo(ass.Location);

It will get the version of the executing assembly (which is the one that
contains the project class; nant.core.dll) not the version of the host
process. So if we are hosted in another process we will return the
correct version information.

Really we want to skip the FileVersionInfo stuff all together and just
go with the assembly information. Why go to the file system when we
already have the assembly loaded with the information we need?

Assembly ass = Assembly.GetExecutingAssembly();
            
Properties.AddReadOnly("nant.filename", ass.Location);
Properties.AddReadOnly("nant.version",
ass.GetName().Version.ToString());
Properties.AddReadOnly("nant.location",
Path.GetDirectoryName(ass.Location));


There is one problem here. The nant.filename should probably be set by
Nant, not the Project. But we need to project to set other information
since it could be created outside the Nant.exe host (nant class).

I'll post a better solution later today.

> -----Original Message-----
> From: [EMAIL PROTECTED]
[mailto:nant-developers-
> [EMAIL PROTECTED]] On Behalf Of Gerry Shaw
> Sent: Wednesday, June 12, 2002 10:01 PM
> To: 'Scott Hernandez'; [EMAIL PROTECTED]; Nant-
> [EMAIL PROTECTED]
> Subject: RE: [nant-dev] Multiple build files error?
> 
> If anybody can find a replace for this chunk of code:
>             ProcessModule module =
> Process.GetCurrentProcess().MainModule;
>             FileVersionInfo versionInfo =
> FileVersionInfo.GetVersionInfo(module.FileName);
>             Properties.AddReadOnly("nant.filename",
> versionInfo.FileName);
>             Properties.AddReadOnly("nant.version",
> versionInfo.FileVersion);
>             Properties.AddReadOnly("nant.location",
> Path.GetDirectoryName(module.FileName));
> 
> I'd love to add it.  I remember thinking this seemed like a hack but I
> couldn't find any other way of getting the filename, version and
> location of the file.
> 
> You could test your theory of locked files by just commenting out this
> code, rebuilding nant (its easy) and running your build file.



_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas - 
http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink

_______________________________________________
Nant-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-developers

Reply via email to