Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / November 2006

Tip: Looking for answers? Try searching our database.

Framework files location for compile

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chuck P - 16 Nov 2006 15:37 GMT
On our development machines I created some batch file for compiling our web
apps.

They make use of some environment variables and batch files that visual
studio installs.
if "%VS80COMNTOOLS%"=="" goto error_no_VS80COMNTOOLS

rem set path of aspnet_compiler for the framework in vs80
call "%VS80COMNTOOLS%vsvars32.bat"

On my machine
VS80COMNTOOLS=C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\

vsvars32.bat sets a lot of environment stuff but,  basically it puts into
the path the location of
 aspnet_compiler and aspnet_regiis

This is great because I don't have to hard code the path or worry about new
paths if the framework gets upgraded.

Unfortunately, I now need to compile on a computer which does not have VS
installed.  Thus no environment variables or vsvars32.bat file.

Is their an automated way to get the most recent path to  aspnet_compiler
and aspnet_regiis?

thanks,
Rad [Visual C# MVP] - 16 Nov 2006 17:30 GMT
Well, one way is to create a small utility that will get the path for you.
This will take you all of 5 seconds. The code is as follows:

public static void Main()
    {
        string location
=System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
        Console.WriteLine(location);
    }

Having done this you can then pipe the output of this utility and use it for
further processing of your batch file
Signature


Bits. Bytes.
http://bytes.thinkersroom.com
------------------------------

> On our development machines I created some batch file for compiling our web
> apps.
[quoted text clipped - 23 lines]
>
> thanks,
Chuck P - 16 Nov 2006 23:23 GMT
Interesting, but I believe that would only get me the directory of the
version being used, not the most recent one.
Rad [Visual C# MVP] - 17 Nov 2006 08:16 GMT
In that case you'll have to do a little more work. You can get the list if
installed Framework Versions from this registry key:

HKEY_LOCAL_MACHINE,"Software\Microsoft\ASP.Net

It will look like so:

ASP.NET
--1.1.4322.0
--2.0.50727.0
--MachineAccounts

You can then enumerate through the subkeys, which are the.NET framework
versions, until you get the one you are interested in. (Sans the last one!)

You can then extract the .NET framework location using the PATH key

Caveat: This will only work if asp.net is installed on the machine, but
since you know this to be the case this shouldn't be too much of a problem
Signature


Bits. Bytes.
http://bytes.thinkersroom.com
------------------------------

> Interesting, but I believe that would only get me the directory of the
> version being used, not the most recent one.
Linda Liu [MSFT] - 17 Nov 2006 11:53 GMT
Hi Chuck,

I agree with you that the following statement will return the path of the
CLR that currently runs the assembly, which maybe not the latest version of
CLR installed on the machine:

string location
=System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();

NET Framework with different versions can be installed side by side on a
machine. When a .NET program runs, it will use the same version of CLR it
is built on, only if this version of CLR has been installed. So it's not
possible to detect the latest version of CLR in a .NET program using any
existing .NET class related to the CLR.

So we must do it by other means.

When we install .NET Framework on a machine, some information is recorded
in the registry. Type "regedit" in the run prompt to open registry editor.
Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework. You will
see an item named "InstallRoot", which records a general path of CLR. The
value of this item on my machine is "C:\WINNT\Microsoft.NET\Framework".

Unfortunately, there is not a value in the registry that contains the path
of the latest version of CLR. But all versions of installed CLR are listed
under the "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\" branch as
sub keys, such as v2.0.50727 and v3.0. Thus, we could get the latest one
and add it to the intall root to get the path of the latest version of CLR.

The following is  a sample.

using Microsoft.Win32;  

private string GetInstallRoot()
 {
           RegistryKey rk = Registry.LocalMachine;
           rk = rk.OpenSubKey("software\\microsoft\\.NetFramework",false);
           string installRoot = rk.GetValue("InstallRoot").ToString();
           return installRoot;
 }
 private string GetLatestVersion()
  {
           // Create a RegistryKey, which will access the
HKEY_LOCAL_MACHINE
           // key in the registry of this machine.
           RegistryKey rk = Registry.LocalMachine;
           rk = rk.OpenSubKey("software\\microsoft\\.NetFramework",false);

           // Retrieve all the subkeys for the specified key.
           String[] names = rk.GetSubKeyNames();

           string latestVersion = "";
           
           foreach (String name in names)
           {
               if (name.StartsWith("v") && name.CompareTo(latestVersion) >
0)
                   latestVersion = name;
           }

           return latestVersion;
  }

Then you could get the path of the latest version of CLR using the
following code.

string path = GetInstallRoot() + GetLatestVersion();

Hope this helps.
If you have any concerns, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Rad [Visual C# MVP] - 17 Nov 2006 15:04 GMT
Hi Linda,

I'd thought of that solution initially but on my machine (Windows 2003
Server SP 1) I know for a fact that it has .NET frameworks 1.1 and 2.0
installed and yet the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework
only shows version 2.0.

The ASP.NET key however correctly lists them all!

Any idea why this is the case?
Signature


Bits. Bytes.
http://bytes.thinkersroom.com
------------------------------

> Hi Chuck,
>
[quoted text clipped - 70 lines]
> Linda Liu
> Microsoft Online Community Support
Ciaran O''Donnell - 20 Nov 2006 12:56 GMT
Because Win2k3 comes with .net 1.1 installed so it doesnt get setup through
and installer. It also comes without asp.net installed so you have to install
that to iis which sets up the registry.

Ciaran O'Donnell

> Hi Linda,
>
[quoted text clipped - 81 lines]
> > Linda Liu
> > Microsoft Online Community Support
Rad [Visual C# MVP] - 20 Nov 2006 16:06 GMT
Then can we therefore conclude that the
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework key cannot
reliably be said to contain any, if all, .NET frameworks?

>Because Win2k3 comes with .net 1.1 installed so it doesnt get setup through
>and installer. It also comes without asp.net installed so you have to install
[quoted text clipped - 87 lines]
>> > Linda Liu
>> > Microsoft Online Community Support
--

Bits.Bytes.
http://bytes.thinkersroom.com
Chuck P - 20 Nov 2006 21:11 GMT
fyi on a 64bit.

hklm\software\Microsoft\.NETFramework
  Key InstallRoot  C:\WINDOWS\Microsoft.NET\Framework64\
  SubKey = v2.0.50727

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.