Пример #1
0
        public void AddProjectReference(CsProj referencedProject)
        {
            if (this == referencedProject)
            {
                return;
            }

            if (ContainsProjectReference(referencedProject))
            {
                return;
            }

            Cauldron.Add($"Adding {referencedProject.Filepath} project reference to {Filepath}");
            Uri mercurySourcePath     = new Uri(Filepath);
            Uri referencedProjectPath = new Uri(referencedProject.Filepath);
            Uri relPath        = mercurySourcePath.MakeRelativeUri(referencedProjectPath);
            var projectRefPath = relPath.ToString().Replace("/", "\\");

            var regex = new Regex(_itemGroupProjectReferencePattern);

            Text = regex.Replace(Text, _itemGroupProjectReference +
                                 "Include=\"" + projectRefPath + "\">" + Environment.NewLine +
                                 "<Project>{" + referencedProject.Guid + "}</Project>" + Environment.NewLine +
                                 "<Name>" + referencedProject.Name + "</Name>" + Environment.NewLine +
                                 "</ProjectReference>" + Environment.NewLine +
                                 "<ProjectReference ", 1);
            WriteFile();
            ReformatXml(Filepath);
            _csProjCache = null;
        }
Пример #2
0
 public void RemoveUsing(string reference)
 {
     Cauldron.Add($"Removing Using: {reference} from {Name}.cs");
     if (Usings.Contains(reference))
     {
         Usings.RemoveAt(Usings.IndexOf(reference));
     }
 }
Пример #3
0
 public void AddUsing(string reference)
 {
     Cauldron.Add($"Add Using: {reference} to {Name}.cs");
     if (!Usings.Contains(reference))
     {
         Usings.Add(reference);
     }
 }
Пример #4
0
        public void RemoveProjectReference(string projectGuid)
        {
            if (ContainsProjectReference(projectGuid))
            {
                Cauldron.Add($"Removing project reference with guid {projectGuid} from {Name}");

                RemoveProjectText(projectGuid);
                RemoveRemainingReferences(projectGuid);

                WriteFile();
                _csProjsCache = null;
            }
            else
            {
                Cauldron.Add($"No project of GUID: {projectGuid} found");
            }
        }
Пример #5
0
        private CsProj[] GetProjectReferences(string[] removedProjects = null)
        {
            Cauldron.Add($"Getting Project references for {Filepath}");
            List <CsProj> dependencies = new List <CsProj>();

            foreach (var csProjRelPath in new Librarian(_csProjPathPattern, Text).Get("capturegroup"))
            {
                if (removedProjects != null && removedProjects.Contains(Path.GetFileName(csProjRelPath)))
                {
                    continue;
                }
                var path           = Path.Combine(Directory.GetParent(Filepath).FullName, csProjRelPath);
                var csProjFullPath = Path.GetFullPath(path);
                dependencies.Add(Get(csProjFullPath));
            }
            return(dependencies.ToArray());
        }
Пример #6
0
 public void RemoveProjectReference(string projectGuid)
 {
     if (ContainsProjectReference(projectGuid))
     {
         Cauldron.Add($"Removing project reference with guid {projectGuid} from {Name}");
         var   pattern = $".*(?:<ProjectReference.+(\\n*\\r*))(?:.*{projectGuid}.*(\\n*\\r*))(?:.+(\\n*\\r*))+?(?:.*<\\/ProjectReference>(\\n*\\r*))";
         Regex regex   = new Regex(pattern, RegexOptions.IgnoreCase);
         Text = regex.Replace(Text, "");
         WriteFile();
         ReformatXml(Filepath);
         _csProjCache = null;
     }
     else
     {
         Cauldron.Add($"No project of GUID: {projectGuid} found");
     }
 }
Пример #7
0
        private NugetPackageReference[] GetNugetProjectDependencies()
        {
            //This needs to be tidied up.
            //Should we get nuget references from packages.config followed by additional info from csproj, or the other way around?

            //Additional problem - How do I map csproj nuget references to packages.config entries. The Id's dont always align?

            Cauldron.Add($"Getting Nuget references for {Filepath}");
            List <NugetPackageReference> nugetReferences = new List <NugetPackageReference>();
            var references = new Librarian(_nugetReferencePattern, Text)
                             .Get("capturegroup")
                             .Where(token => token.Contains("\\packages\\")); //i.e. ignore any "lib" references. Cant exclued by !contains(lib) as all packages have a lib folder

            foreach (var reference in references)
            {
                var dllName = new Librarian(_nugetDllNameFromNugetReferencePattern, reference)
                              .Get("capturegroup")
                              .Single();

                var nugetId = new Librarian(_nugetIdFromNugetReferencePattern, reference)
                              .Get("capturegroup")
                              .Single()
                              .TrimEnd('.');

                var hintPath = new Librarian(_nugetHintPathPattern, reference)
                               .Get("capturegroup")
                               .Single();

                var include = new Librarian(_nugetIncludeFromNugetReferencePattern, reference)
                              .Get("capturegroup")
                              .Single();

                var pc = PackagesConfig();
                var nr = pc
                         .NugetpackageReferences;
                var packagesConfigEntry = nr
                                          .Single(entry => string.Equals(entry.Id, nugetId, StringComparison.InvariantCultureIgnoreCase));

                var nugetReference = new NugetPackageReference(nugetId, dllName, hintPath, include, packagesConfigEntry);
                nugetReferences.Add(nugetReference);
            }
            return(nugetReferences.ToArray());
        }
Пример #8
0
        public void AlphabatiseUsings()//TODO I don't think this has use anymore, if we want to retain this functionality i suggest trying to embed it into the Removal/Adding process.
        {
            Cauldron.Add($"Alphabatise Usings for {Name}.cs");
            var systemUsings = Usings.Where(@using => new Librarian("(?<!\\.)System\\.*", @using).HasMatch());
            var otherUsings  = Usings.Where(@using => !new Librarian("(?<!\\.)System\\.*", @using).HasMatch());

            foreach (var @using in Usings)
            {
                RemoveUsing(@using);
            }
            foreach (var @using in otherUsings.OrderByDescending(u => u))
            {
                AddUsing(@using);
            }
            foreach (var @using in systemUsings.OrderByDescending(u => u))
            {
                AddUsing(@using);
            }
        }
Пример #9
0
        internal void AddPackageEntry(NugetPackageReference referenceToAdd)
        {
            if (ContainsEntry(referenceToAdd))
            {
                return;
            }

            Cauldron.Add($"Adding Package Entry {referenceToAdd.Id} to {FilePath}");
            var regex = new Regex(_packagesTag);

            Text = regex.Replace(Text, _packagesTag +
                                 Environment.NewLine +
                                 $"<package id=\"{referenceToAdd.Id}\" " +
                                 $"version=\"{referenceToAdd.Version}\" " +
                                 $"targetFramework=\"{referenceToAdd.TargetFramework}\" />");

            File.WriteAllText(FilePath, Text);

            ReformatXml();
        }
Пример #10
0
        public bool HasEvidenceOf(CsProj csProj)
        {
            throw new NotImplementedException(); //https://github.com/Jordan466/ItsMagic/issues/21

            foreach (var @class in csProj.Classes())
            {
                if (new Librarian("[\\s:]" + @class + "[\\s\\.(]", Text).HasMatch())
                {
                    Cauldron.Add($"Found Evidence of {csProj.Name}.{@class} in {Name}.cs");
                    return(true);
                }
            }
            //foreach(var extensionMethod in csProj.ExtensionMethods)
            //{
            //    if (RegexStore.Contains("\\." + extensionMethod + "\\(", Text()))
            //    {
            //        return true;
            //    }
            //}
            return(false);
        }
Пример #11
0
        public void AddNugetReference(NugetPackageReference referenceToAdd)
        {
            if (ContainsNugetProjectReference(referenceToAdd))
            {
                return;
            }

            Cauldron.Add($"Adding nuget Reference to {Filepath}");
            var isCopyLocal = IsHost();
            var regex       = new Regex(_itemGroupTag);

            Text = regex.Replace(Text, _itemGroupTag + Environment.NewLine +
                                 $"<Reference Include=\"{referenceToAdd.Include}\">" + Environment.NewLine +
                                 $"<HintPath>{referenceToAdd.HintPath}</HintPath>" + Environment.NewLine +
                                 $"<Private>{isCopyLocal}</Private>" + Environment.NewLine +
                                 "</Reference>" + Environment.NewLine
                                 , 1);
            WriteFile();
            ReformatXml(Filepath);
            PackagesConfig().AddPackageEntry(referenceToAdd);
            _NuPkgCache = null;
        }