|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Framework files location for compileapps. 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, 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 Show quote "Chuck P" wrote: > 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, > > > > Interesting, but I believe that would only get me the directory of the
version being used, not the most recent one. 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 Show quote "Chuck P" wrote: > Interesting, but I believe that would only get me the directory of the > version being used, not the most recent one. > 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. 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? Show quote "Linda Liu [MSFT]" wrote: > 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 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 Show quote "Rad [Visual C# MVP]" wrote: > 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? > -- > > > Bits. Bytes. > http://bytes.thinkersroom.com > ------------------------------ > > > "Linda Liu [MSFT]" wrote: > > > 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 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? On Mon, 20 Nov 2006 04:56:01 -0800, Ciaran O''Donnell <CiaranODonn***@discussions.microsoft.com> wrote: Show quote >Because Win2k3 comes with .net 1.1 installed so it doesnt get setup through Bits.Bytes.>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 > >"Rad [Visual C# MVP]" wrote: > >> 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? >> -- >> >> >> Bits. Bytes. >> http://bytes.thinkersroom.com >> ------------------------------ >> >> >> "Linda Liu [MSFT]" wrote: >> >> > 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 -- http://bytes.thinkersroom.com |
|||||||||||||||||||||||