public void SaveStructureDefinition(StructureDefinition sd) { // Ensure the folder exists Uri t = new Uri(sd.Url); string profileOutputDirectory = Path.Combine(_outputProfilePath, t.Host); if (!Directory.Exists(profileOutputDirectory)) { Directory.CreateDirectory(profileOutputDirectory); } // Non extensions will just go in the root of the output if (sd.BaseDefinition != "http://hl7.org/fhir/StructureDefinition/Extension") { profileOutputDirectory = _outputProfilePath; } // Now output the file System.IO.File.WriteAllText($"{profileOutputDirectory}/StructureDefinition-{sd.Id}.xml", new FhirXmlSerializer(new SerializerSettings() { AppendNewLine = true, Pretty = true }).SerializeToString(sd)); // And add it to our resolver sourceSD.InvalidateByCanonicalUri(sd.Url); ds.Refresh(); // And check that it comes back... var instSD = sourceSD.ResolveByUri(sd.Url) as StructureDefinition; if (instSD == null) { Console.WriteLine($"Was not able to resolve the newly created extension"); } }