The attached patch file adds some code to WebMapCollection's FindBestMatch method. It the url is not found in the map, it will then look in the registry for the location of local webs.

This really helps since VS.Net soemtimes modifies the name of the web when you check it out. Also, on a large project some developers may put their webs in different locations. Having NANT find the web from the registry is a lot better than trying to keep build files in synch with the local directory structure.

Please let me know if this is incorporated into the official NANT source.

Enjoy!

*** WebMapCollection.cs 2004-07-20 20:06:52.000000000 -0500
--- C:\dev\dotnet\tools\nant-0.85-rc3\src\NAnt.VSNet\Types\WebMapCollection.cs 2005-08-05 13:13:07.130661000 -0500
***************
*** 20,25 ****
--- 20,28 ----
 using System;
 using System.Collections;
 using System.Globalization;
+ using System.Text;
+ using System.Text.RegularExpressions;
+ using Microsoft.Win32;

 namespace NAnt.VSNet.Types {
     /// <summary>
***************
*** 107,112 ****
--- 110,145 ----
                 }
             }

+                       if (bestMatch == null)
+                       {
+                               // not found
+                               // try to find local urls in the registry 
settings for IIS
+                               try
+                               {
+                                       Uri url = new Uri( uri );
+ if ( url.Scheme.StartsWith("http") && (url.Host.Equals("localhost") || url.Host.Equals("128.0.0.1") ) )
+                                       {
+ string virtualRoot = "/" + url.AbsolutePath.Substring(1, url.AbsolutePath.IndexOf('/',1) - 1); + RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\W3SVC\\Parameters\\Virtual Roots" );
+                                               if ( regkey != null )
+                                               {
+                                                       string path = 
Convert.ToString(regkey.GetValue( virtualRoot ));
+                                                       if ( path != null )
+                                                       {
+                                                               Regex regex = new 
Regex("(.*),[^,]*,.*$");
+                                                               Match match = 
regex.Match( path );
+                                                               if ( 
match.Success )
+                                                               {
+ bestMatch = match.Groups[1].ToString() + "\\" + url.AbsolutePath.Substring(url.AbsolutePath.IndexOf('/',1)+1) + url.Query;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               } catch ( UriFormatException )
+                               {
+                                       // expected, do nothing
+                               }
+                       }
             return bestMatch;
         }


Reply via email to