private XDocument GetDocument(bool createIfNotExists = false)
{
try
{
// If the file exists then open and return it
if (FileSystem.FileExists(_path))
{
using (Stream stream = FileSystem.OpenFile(_path))
{
return XDocument.Load(stream);
}
}
// If it doesn't exist and we're creating a new file then return a
// document with an empty packages node
if (createIfNotExists)
{
return new XDocument(new XElement("packages"));
}
return null;
}
catch (XmlException e)
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture, NuGetResources.ErrorReadingFile, FileSystem.GetFullPath(_path)), e);
}
}
}