private void PrepareForStart() { if (!Directory.Exists(_wwwroot)) { Directory.CreateDirectory(_wwwroot); } var binDirectory = Path.Combine(_wwwroot, "bin"); if (!Directory.Exists(binDirectory)) { Directory.CreateDirectory(binDirectory); } CopyFileToDirectory(ConfigTransformPath, _wwwroot); CopyFileToDirectory(typeof(IisExpress).Assembly.Location, binDirectory); var document = new XmlTransformableDocument(); document.LoadXml(WebConfigTemplate); using (var transform = new XmlTransformation(ConfigTransformPath)) { transform.Apply(document); } var list = document.SelectNodes("//*[@configSource]"); if (list != null) { foreach (var node in list.Cast <XmlNode>()) { var source = document.CreateDocumentFragment(); source.InnerXml = File.ReadAllText(node.Attributes["configSource"].Value); var newNode = source.ChildNodes.Cast <XmlNode>().First(x => x.NodeType == XmlNodeType.Element); node.ParentNode.ReplaceChild(newNode, node); } } document.Save(Path.Combine(_wwwroot, "Web.config")); }