Beispiel #1
0
        public static Project ReadFrom(string file)
        {
            if (Path.GetExtension(file) != ".csproj")
            {
                throw new ArgumentOutOfRangeException("You can only use the csproj file here");
            }

            file = file.ToFullPath();
            var project = new Project(file);

            var packagesFile = project.PackagesFile();
            if (new FileSystem().FileExists(packagesFile))
            {
                project._nugetDependencies.AddRange(NugetDependency.ReadFrom(packagesFile));
            }

            return project;
        }
Beispiel #2
0
        public void RemoveFromProject(Project project, IEnumerable<NugetDependency> dependencies)
        {
            var projectManager = buildProjectManager(project);
            var document = new XmlDocument();

            // Don't do anything if packages.config does not exist.  Duh.
            if (!File.Exists(project.PackagesFile())) return;

            document.Load(project.PackagesFile());

            dependencies.Each(dep =>
            {
                ConsoleWriter.Write("Trying to remove {0} from {1}", dep, project.ProjectName);
                projectManager.RemovePackageReference(_packages[dep], true, false);

                var element =
                    document.DocumentElement.SelectSingleNode("package[@id='{0}' and @version='{1}']".ToFormat(
                        dep.Name, dep.Version));

                if (element != null)
                {
                    document.DocumentElement.RemoveChild(element);
                    document.Save(project.PackagesFile());
                }
            });
        }