是否有一种通用方法来访问本地计算机csproj.user文件以获取用于watin测试的网站URL,以便测试可以在每个开发人员本地服务器以及构建服务器上的IIS上运行?我想你可以自己解析xml文件,但我想知道是否有更清洁/更简单的方法。
答案 0 :(得分:1)
我发现了这个
Starting ASP.NET Development Web Server (Cassini) as part of unit test setup?
最后只是通过从我的测试项目到我的Web项目的相对路径来做这样的事情。然后在构建服务器上设置适当的csproj.user文件。
public static string GetDevelopmentServerURL(string csprojFileName) { XPathDocument doc = new XPathDocument(csprojFileName); XPathNavigator navigator = doc.CreateNavigator();
XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);
manager.AddNamespace("msbuild",
"http://schemas.microsoft.com/developer/msbuild/2003");
const string xpath = "/msbuild:Project/msbuild:ProjectExtensions/"
+ "msbuild:VisualStudio/msbuild:FlavorProperties/"
+ "msbuild:WebProjectProperties";
XPathNavigator webProjectPropertiesNode =
navigator.SelectSingleNode(xpath, manager);
XPathNavigator developmentServerPortNode =
webProjectPropertiesNode.SelectSingleNode("msbuild:DevelopmentServerPort",
manager);
XPathNavigator developmentServerVPathNode =
webProjectPropertiesNode.SelectSingleNode("msbuild:DevelopmentServerVPath",
manager);
XPathNavigator UseIIS =webProjectPropertiesNode.SelectSingleNode("msbuild:UseIIS",
manager);
XPathNavigator IISPath = webProjectPropertiesNode.SelectSingleNode("msbuild:IISUrl",
manager);
XPathNavigator UseCustomServer = webProjectPropertiesNode.SelectSingleNode("msbuild:UseCustomServer",manager);
XPathNavigator CustomeServerPath = webProjectPropertiesNode.SelectSingleNode("msbuild:CustomServerUrl",
manager);
if (UseIIS.Value == "True")
return IISPath.Value;
if (UseCustomServer.Value == "True")
return CustomeServerPath.Value;
return "http://localhost:" + developmentServerPortNode.Value + developmentServerVPathNode;
}