Exemplo n.º 1
0
        protected virtual IList <string> GetSourceFiles(XDocument doc)
        {
            this.Log.Trace("Getting source files by xml...");

            Project        project;
            IList <string> sourceFiles = new List <string>();

            if (this.Source == null)
            {
                var isOnMono = Translator.IsRunningOnMono();
                if (isOnMono)
                {
                    // Using XmlReader here addresses a Mono issue logged as #38224 at Mono's official BugZilla.
                    // Bridge issue #860
                    // This constructor below works on Linux and DOES break #531
                    project = new Project(XmlReader.Create(this.Location), null, null, new ProjectCollection());
                }
                else
                {
                    // Using XmlReader above breaks feature #531 - referencing linked files in csproj (Compiler test 18 fails)
                    // To avoid it at least on Windows, use different Project constructors
                    // This constructor below works on Windows and does NOT break #531
                    project = new Project(this.Location, null, null, new ProjectCollection());
                }

                foreach (var projectItem in project.GetItems("Compile"))
                {
                    sourceFiles.Add(projectItem.EvaluatedInclude);
                }

                if (isOnMono)
                {
                    // This UnloadProject overload should be used if the project created by new Project(XmlReader.Create(this.Location)...)
                    // Otherwise it does NOT work either on Windows or Linux
                    project.ProjectCollection.UnloadProject(project.Xml);
                }
                else
                {
                    // This UnloadProject overload should be used if the project created by new Project(this.Location...)
                    // Otherwise it does NOT work either on Windows or Linux
                    project.ProjectCollection.UnloadProject(project);
                }

                if (!sourceFiles.Any())
                {
                    throw new Bridge.Translator.TranslatorException("Unable to get source file list from project file '" +
                                                                    this.Location + "'. In order to use bridge, you have to have at least one source code file " +
                                                                    "with the 'compile' property set (usually .cs files have it by default in C# projects).");
                }
                ;
            }
            else
            {
                sourceFiles = GetSourceFiles(Path.GetDirectoryName(this.Location));
            }

            this.Log.Trace("Getting source files by xml done");

            return(sourceFiles);
        }
Exemplo n.º 2
0
        internal static void CloseProject(Project project)
        {
            bool isOnMono = Translator.IsRunningOnMono();

            if (isOnMono)
            {
                // This UnloadProject overload should be used if the project created by new Project(XmlReader.Create(this.Location)...)
                // Otherwise it does NOT work either on Windows or Linux
                project.ProjectCollection.UnloadProject(project.Xml);
            }
            else
            {
                // This UnloadProject overload should be used if the project created by new Project(this.Location...)
                // Otherwise it does NOT work either on Windows or Linux
                project.ProjectCollection.UnloadProject(project);
            }
        }