/// <summary>
        /// Extracts the repository path from a nuget.config settings file
        /// </summary>
        /// <param name="path">Full path to the nuget.config file</param>
        private string GetRepositoryPathFromConfig(string path)
        {
            try
            {
                XDocument document;
                using (Stream stream = FileSystem.OpenFile(path))
                {
                    document = XmlUtility.LoadSafe(stream);
                }

                // <settings>
                //    <repositoryPath>..</repositoryPath>
                // </settings>
                string repositoryPath = document.Root.GetOptionalElementValue("repositoryPath");
                if (!String.IsNullOrEmpty(repositoryPath))
                {
                    repositoryPath = repositoryPath.Replace('/', Path.DirectorySeparatorChar);
                }
                return(repositoryPath);
            }
            catch (XmlException e)
            {
                // Set the configuration path to null if it fails
                _configurationPath = null;

                // If we were unable to parse the configuration file then show an error
                throw new InvalidOperationException(
                          String.Format(CultureInfo.CurrentCulture,
                                        VsResources.ErrorReadingFile, path), e);
            }
        }
Beispiel #2
0
        internal static List <AssemblyName> GetFrameworkAssemblies(IFileSystem fileSystemFrameworkListFile)
        {
            List <AssemblyName> frameworkAssemblies = new List <AssemblyName>();

            try
            {
                if (fileSystemFrameworkListFile.FileExists(FrameworkListFileName))
                {
                    using (Stream stream = fileSystemFrameworkListFile.OpenFile(FrameworkListFileName))
                    {
                        var document = XmlUtility.LoadSafe(stream);
                        var root     = document.Root;
                        if (root.Name.LocalName.Equals("FileList", StringComparison.OrdinalIgnoreCase))
                        {
                            foreach (var element in root.Elements("File"))
                            {
                                string simpleAssemblyName = element.GetOptionalAttributeValue("AssemblyName");
                                string version            = element.GetOptionalAttributeValue("Version");
                                if (simpleAssemblyName == null || version == null)
                                {
                                    // Skip this file. Return an empty list
                                    // Clear frameworkAssemblies since we don't want partial results
                                    frameworkAssemblies.Clear();
                                    break;
                                }
                                else
                                {
                                    AssemblyName assemblyName = new AssemblyName();
                                    assemblyName.Name    = simpleAssemblyName;
                                    assemblyName.Version = new Version(version);
                                    frameworkAssemblies.Add(assemblyName);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            return(frameworkAssemblies);
        }
Beispiel #3
0
 internal virtual XDocument LoadDocument(string path)
 {
     return(XmlUtility.LoadSafe(path));
 }