internal static void AddReferencesToConfig(NuGet.IFileSystem fileSystem, string references)
        {
            var       webConfigPath = Path.Combine(fileSystem.Root, "web.config");
            XDocument document;

            // Read the web.config file from the AppRoot if it exists.
            if (fileSystem.FileExists(webConfigPath))
            {
                using (Stream stream = fileSystem.OpenFile(webConfigPath))
                {
                    document = XDocument.Load(stream, LoadOptions.PreserveWhitespace);
                }
            }
            else
            {
                document = new XDocument(new XElement("configuration"));
            }

            var assemblies = GetOrCreateChild(document.Root, "system.web/compilation/assemblies");

            // Get the name of the existing references
            // References are stored in the format <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            bool existingAssembly = (from item in assemblies.Elements()
                                     where !String.IsNullOrEmpty(item.GetOptionalAttributeValue("assembly"))
                                     let assemblyName = new AssemblyName(item.Attribute("assembly").Value).Name
                                                        where String.Equals(assemblyName, references, StringComparison.OrdinalIgnoreCase)
                                                        select item).Any();

            if (!existingAssembly)
            {
                assemblies.Add(new XElement("add", new XAttribute("assembly", references)));
                SaveDocument(fileSystem, webConfigPath, document);
            }
        }
 private static void SaveDocument(NuGet.IFileSystem fileSystem, string webConfigPath, XDocument document)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         document.Save(stream);
         stream.Seek(0, SeekOrigin.Begin);
         fileSystem.AddFile(webConfigPath, stream);
     }
 }
 public AppCommandsFolderRepository(string commandsFolder)
 {
     _commandsFolder = new NuGet.PhysicalFileSystem(commandsFolder);
     _pathResolver   = new DefaultPackagePathResolver(_commandsFolder);
 }
 public AppCommandsFolderRepository(string commandsFolder)
 {
     _commandsFolder = new NuGet.PhysicalFileSystem(commandsFolder);
     _pathResolver = new DefaultPackagePathResolver(commandsFolder);
 }
 public BetterThanLocalPackageRepository(IPackagePathResolver pathResolver, IFileSystem fileSystem, MSBuildProjectSystem projectSystem)
     : base(pathResolver, fileSystem)
 {
     _projectSystem = projectSystem;
 }
Exemple #6
0
 public BetterThanLocalPackageRepository(IPackagePathResolver pathResolver, IFileSystem fileSystem, MSBuildProjectSystem projectSystem) : base(pathResolver, fileSystem)
 {
     _projectSystem = projectSystem;
 }