Windows Azure で WebRole を起動する一環として、起動中の Web サイトのファイルにアクセスしたいと考えており、これを RoleEntryPoint.OnStart() で実行したいと考えています。これにより、たとえば、ASP.NET AppDomain が読み込まれる前に ASP.NET 構成に影響を与えることができます。
Azure SDK 1.3 と VS2010 を使用してローカルで実行する場合、以下のサンプル コードはトリックを実行しますが、コードにはハッキングの悪臭があり、Azure にデプロイするときはトリックを実行しません。
XNamespace srvDefNs = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition";
DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
string roleRoot = di.Parent.Parent.FullName;
XDocument roleModel = XDocument.Load(Path.Combine(roleRoot, "RoleModel.xml"));
var propertyElements = roleModel.Descendants(srvDefNs + "Property");
XElement sitePhysicalPathPropertyElement = propertyElements.Attributes("name").Where(nameAttr => nameAttr.Value == "SitePhysicalPath").Single().Parent;
string pathToWebsite = sitePhysicalPathPropertyElement.Attribute("value").Value;
開発者と Azure の両方で機能する方法で RoleEntryPoint.OnStart() から WebRole サイトのルート パスを取得するにはどうすればよいですか?