Example #1
0
        private int RemoveAssembliesReferences()
        {
            ReadRunSourceProjectAssembliesReferences();
            int assemblyReferenceRemovedCount = 0;

            // ToArray() is needed because XDocument is modified by RemoveAssemblyReference()
            foreach (VSReference reference in _vsProjectManager.GetReferences().ToArray())
            {
                if (reference.ProjectReference)
                {
                    continue;
                }
                if (!_runsourceProjectAssembliesReferences.ContainsKey(reference.Name.ToLower()))
                {
                    if (_vsProjectManager.RemoveAssemblyReference(reference.Name))
                    {
                        Trace.WriteLine($"  remove reference \"{reference.Name}\"");
                    }
                    else
                    {
                        Trace.WriteLine($"  warning can't remove reference, reference not found \"{reference.Name}\"");
                    }
                    assemblyReferenceRemovedCount++;
                }
            }
            return(assemblyReferenceRemovedCount);
        }
Example #2
0
        public static void TraceVSProject(string vsProject = null)
        {
            if (vsProject != null)
            {
                vsProject = RunSourceCommand.GetFilePath(RunSourceCommand.GetProjectVariableValue(vsProject));
            }
            else
            {
                vsProject = GetVSProject(RunSourceCommand.GetCurrentProject());
            }

            if (!zFile.Exists(vsProject))
            {
                Trace.WriteLine($"visual studio project not found \"{vsProject}\"");
                return;
            }

            try
            {
                //RunSourceCommand.TraceDisableViewer();
                ////RunSourceCommand.TraceSetWriter(WriteToFile.Create(zPath.Combine(zPath.GetDirectoryName(vsProject), zPath.GetFileName(vsProject) + ".trace.txt"), FileOption.RazFile), "trace");
                //RunSourceCommand.TraceSetWriter(WriteToFile.Create(vsProject + ".trace.txt", FileOption.RazFile), "trace");
                RunSourceCommand.TraceManager.DisableViewer();
                RunSourceCommand.TraceManager.SetWriter(WriteToFile.Create(vsProject + ".trace.txt", FileOption.RazFile), "trace");

                Trace.WriteLine($"visual studio project \"{vsProject}\"");
                VSProjectManager vsProjectManager = new VSProjectManager(vsProject);
                Trace.WriteLine("  sources");
                foreach (VSSource source in vsProjectManager.GetSources().Where(source => source.Link == null).OrderBy(source => source.File))
                {
                    //Trace.WriteLine($"    file \"{sourceLink.File}\" link \"{sourceLink.Link}\"");
                    //if (source.Link == null)
                    Trace.WriteLine($"    \"{source.File}\"");
                }
                Trace.WriteLine("  sources links");
                foreach (VSSource source in vsProjectManager.GetSources().Where(source => source.Link != null).OrderBy(source => source.File))
                {
                    //Trace.WriteLine($"    file \"{sourceLink.File}\" link \"{sourceLink.Link}\"");
                    //if (source.Link != null)
                    Trace.WriteLine($"    \"{source.File}\"");
                }
                Trace.WriteLine("  framework references");
                foreach (VSReference reference in vsProjectManager.GetReferences().Where(reference => reference.File == null).OrderBy(reference => reference.Name))
                {
                    Trace.WriteLine($"    \"{reference.Name}\"");
                }
                Trace.WriteLine("  dll references");
                foreach (VSReference reference in vsProjectManager.GetReferences().Where(reference => reference.File != null && !reference.ProjectReference).OrderBy(reference => reference.Name))
                {
                    Trace.WriteLine($"    {("\"" + reference.Name + "\""),-70} \"{reference.File}\"");
                    //if (reference.File == null)
                    //    Trace.WriteLine($"    \"{reference.Name}\"");
                    //else if (reference.ProjectReference)
                    //    //Trace.WriteLine($"    \"{reference.Name}\" \"{reference.File}\" project \"{reference.ProjectReference}\"");
                    //    Trace.WriteLine($"    \"{reference.Name,-70}\" \"{reference.File}\"");
                    //else
                    //    Trace.WriteLine($"    \"{reference.Name,-70}\" \"{reference.File}\"");
                }
                Trace.WriteLine("  project references");
                foreach (VSReference reference in vsProjectManager.GetReferences().Where(reference => reference.ProjectReference).OrderBy(reference => reference.Name))
                {
                    Trace.WriteLine($"    {("\"" + reference.Name + "\""),-70} \"{reference.File}\"");
                }
            }
            finally
            {
                //RunSourceCommand.TraceRemoveWriter("trace");
                //RunSourceCommand.TraceEnableViewer();
                RunSourceCommand.TraceManager.RemoveWriter("trace");
                RunSourceCommand.TraceManager.EnableViewer();
            }
        }