コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the MSBuildProjectLoader class.
 /// </summary>
 /// <param name="globalProperties">Specifies the global properties to use when loading projects.</param>
 /// <param name="toolsVersion">Specifies the ToolsVersion to use when loading projects.</param>
 /// <param name="projectLoadSettings">Specifies the <see cref="ProjectLoadSettings"/> to use when loading projects.</param>
 /// <param name="log"></param>
 public MSBuildProjectLoader(IDictionary <string, string> globalProperties, string toolsVersion, TaskLoggingHelper log, ProjectLoadSettings projectLoadSettings = ProjectLoadSettings.Default)
 {
     _globalProperties    = globalProperties;
     _toolsVersion        = toolsVersion;
     _projectLoadSettings = projectLoadSettings;
     _log = log ?? throw new ArgumentNullException(nameof(log));
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MSBuildProjectLoader"/> class.
 /// </summary>
 /// <param name="globalProperties">Specifies the global properties to use when loading projects.</param>
 /// <param name="toolsVersion">Specifies the ToolsVersion to use when loading projects.</param>
 /// <param name="buildEngine">An <see cref="IBuildEngine"/> object to use for logging.</param>
 /// <param name="projectLoadSettings">Specifies the <see cref="ProjectLoadSettings"/> to use when loading projects.</param>
 public MSBuildProjectLoader(IDictionary <string, string> globalProperties, string toolsVersion, IBuildEngine buildEngine, ProjectLoadSettings projectLoadSettings = ProjectLoadSettings.Default)
 {
     _globalProperties    = globalProperties;
     _toolsVersion        = toolsVersion;
     _projectLoadSettings = projectLoadSettings;
     _buildEngine         = buildEngine ?? throw new ArgumentNullException(nameof(buildEngine));
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MSBuildProjectLoader"/> class.
 /// </summary>
 /// <param name="globalProperties">Specifies the global properties to use when loading projects.</param>
 /// <param name="toolsVersion">Specifies the ToolsVersion to use when loading projects.</param>
 /// <param name="buildEngine">An <see cref="IBuildEngine"/> object to use for logging.</param>
 /// <param name="projectLoadSettings">Specifies the <see cref="ProjectLoadSettings"/> to use when loading projects.</param>
 public MSBuildProjectLoader(IDictionary <string, string> globalProperties, string toolsVersion, IBuildEngine buildEngine, ProjectLoadSettings projectLoadSettings = ProjectLoadSettings.Default)
 {
     _globalProperties    = globalProperties;
     _toolsVersion        = toolsVersion;
     _projectLoadSettings = projectLoadSettings;
     ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), nameof(buildEngine), buildEngine);
     _buildEngine = buildEngine;
 }
コード例 #4
0
        public Project LoadInMemoryWithSettings(string content, ProjectLoadSettings settings = ProjectLoadSettings.Default)
        {
            content = ObjectModelHelpers.CleanupFileContents(content);
            ProjectRootElement xml     = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            Project            project = new Project(xml, null, null, this.Collection, settings);

            return(project);
        }
コード例 #5
0
ファイル: Project.cs プロジェクト: mono-soc-2011/mono
 public Project(ProjectRootElement xml, IDictionary <string, string> globalProperties,
                string toolsVersion, ProjectCollection projectCollection,
                ProjectLoadSettings loadSettings)
 {
     ProjectCollection = projectCollection;
     Xml = xml;
     GlobalProperties = globalProperties;
     ToolsVersion     = toolsVersion;
 }
コード例 #6
0
ファイル: Project.cs プロジェクト: ngraziano/mono
 public Project (ProjectRootElement xml, IDictionary<string, string> globalProperties,
                 string toolsVersion, ProjectCollection projectCollection,
                 ProjectLoadSettings loadSettings)
 {
         ProjectCollection = projectCollection;
         Xml = xml;
         GlobalProperties = globalProperties;
         ToolsVersion = toolsVersion;
 }
コード例 #7
0
ファイル: BuildParameters.cs プロジェクト: xen2/msbuild
        /// <summary>
        /// Copy constructor
        /// </summary>
        internal BuildParameters(BuildParameters other, bool resetEnvironment = false)
        {
            ErrorUtilities.VerifyThrowInternalNull(other, nameof(other));

            _buildId                 = other._buildId;
            _culture                 = other._culture;
            _defaultToolsVersion     = other._defaultToolsVersion;
            _enableNodeReuse         = other._enableNodeReuse;
            _buildProcessEnvironment = resetEnvironment
                ? CommunicationsUtilities.GetEnvironmentVariables()
                : other._buildProcessEnvironment != null
                    ? new Dictionary <string, string>(other._buildProcessEnvironment)
                    : null;
            _environmentProperties = other._environmentProperties != null ? new PropertyDictionary <ProjectPropertyInstance>(other._environmentProperties) : null;
            _forwardingLoggers     = other._forwardingLoggers != null ? new List <ForwardingLoggerRecord>(other._forwardingLoggers) : null;
            _globalProperties      = other._globalProperties != null ? new PropertyDictionary <ProjectPropertyInstance>(other._globalProperties) : null;
            HostServices           = other.HostServices;
            _loggers               = other._loggers != null ? new List <ILogger>(other._loggers) : null;
            _maxNodeCount          = other._maxNodeCount;
            _memoryUseLimit        = other._memoryUseLimit;
            _nodeExeLocation       = other._nodeExeLocation;
            NodeId                 = other.NodeId;
            _onlyLogCriticalEvents = other._onlyLogCriticalEvents;
#if FEATURE_THREAD_PRIORITY
            BuildThreadPriority = other.BuildThreadPriority;
#endif
            _toolsetProvider           = other._toolsetProvider;
            ToolsetDefinitionLocations = other.ToolsetDefinitionLocations;
            _toolsetProvider           = other._toolsetProvider;
            _uiCulture      = other._uiCulture;
            DetailedSummary = other.DetailedSummary;
            _shutdownInProcNodeOnBuildFinish = other._shutdownInProcNodeOnBuildFinish;
            ProjectRootElementCache          = other.ProjectRootElementCache;
            ResetCaches = other.ResetCaches;
            LegacyThreadingSemantics      = other.LegacyThreadingSemantics;
            SaveOperatingEnvironment      = other.SaveOperatingEnvironment;
            _useSynchronousLogging        = other._useSynchronousLogging;
            _disableInProcNode            = other._disableInProcNode;
            _logTaskInputs                = other._logTaskInputs;
            _logInitialPropertiesAndItems = other._logInitialPropertiesAndItems;
            WarningsAsErrors              = other.WarningsAsErrors == null ? null : new HashSet <string>(other.WarningsAsErrors, StringComparer.OrdinalIgnoreCase);
            WarningsAsMessages            = other.WarningsAsMessages == null ? null : new HashSet <string>(other.WarningsAsMessages, StringComparer.OrdinalIgnoreCase);
            _projectLoadSettings          = other._projectLoadSettings;
            _interactive            = other._interactive;
            _isolateProjects        = other._isolateProjects;
            _inputResultsCacheFiles = other._inputResultsCacheFiles;
            _outputResultsCacheFile = other._outputResultsCacheFile;
            DiscardBuildResults     = other.DiscardBuildResults;
            LowPriority             = other.LowPriority;
            ProjectCacheDescriptor  = other.ProjectCacheDescriptor;
        }
コード例 #8
0
        /// <summary>
        /// Loads the project references of the specified project.
        /// </summary>
        /// <param name="project">The <see cref="Project"/> to load the references of.</param>
        /// <param name="projectLoadSettings">Specifies the <see cref="ProjectLoadSettings"/> to use when loading projects.</param>
        private void LoadProjectReferences(Project project, ProjectLoadSettings projectLoadSettings)
        {
            IEnumerable <ProjectItem> projects = project.GetItems(ProjectReferenceItemName);

            if (IsTraveralProject(project))
            {
                projects = projects.Concat(project.GetItems(TraveralProjectFileItemName));
            }
            Parallel.ForEach(projects, projectReferenceItem =>
            {
                string projectReferencePath = Path.IsPathRooted(projectReferenceItem.EvaluatedInclude) ? projectReferenceItem.EvaluatedInclude : Path.GetFullPath(Path.Combine(projectReferenceItem.Project.DirectoryPath, projectReferenceItem.EvaluatedInclude));
                LoadProject(projectReferencePath, projectReferenceItem.Project.ProjectCollection, projectLoadSettings);
            });
        }
コード例 #9
0
ファイル: Project.cs プロジェクト: pmq20/mono_forked
        public Project(ProjectRootElement xml, IDictionary <string, string> globalProperties,
                       string toolsVersion, ProjectCollection projectCollection,
                       ProjectLoadSettings loadSettings)
        {
            if (projectCollection == null)
            {
                throw new ArgumentNullException("projectCollection");
            }
            this.Xml = xml;
            this.GlobalProperties  = globalProperties ?? new Dictionary <string, string> ();
            this.ToolsVersion      = toolsVersion;
            this.ProjectCollection = projectCollection;
            this.load_settings     = loadSettings;

            Initialize();
        }
コード例 #10
0
        /// <summary>
        /// Gets a <see cref="Project" /> instance from the current project.
        /// </summary>
        /// <param name="project">Receives the <see cref="Project" /> instance.</param>
        /// <param name="globalProperties">Optional <see cref="IDictionary{String, String}" /> containing global properties.</param>
        /// <param name="toolsVersion">Optional tools version.</param>
        /// <param name="projectCollection">Optional <see cref="ProjectCollection" /> to use.  Defaults to <code>ProjectCollection.GlobalProjectCollection</code>.</param>
        /// <param name="projectLoadSettings">Optional <see cref="ProjectLoadSettings" /> to use.  Defaults to <see cref="ProjectLoadSettings.Default" />.</param>
        /// <returns>The current <see cref="ProjectCreator" />.</returns>
        public ProjectCreator TryGetProject(
            out Project project,
            IDictionary <string, string>?globalProperties = null,
            string?toolsVersion = null,
            ProjectCollection?projectCollection     = null,
            ProjectLoadSettings projectLoadSettings = ProjectLoadSettings.Default)
        {
            project = new Project(
                RootElement,
                globalProperties,
                toolsVersion ?? (string.IsNullOrEmpty(RootElement.ToolsVersion) ? null : RootElement.ToolsVersion),
                projectCollection ?? ProjectCollection,
                projectLoadSettings);

            return(this);
        }
コード例 #11
0
        /// <summary>
        /// Gets a <see cref="Project"/> instance from the current project.
        /// </summary>
        /// <param name="project">Receives the <see cref="Project"/> instance.</param>
        /// <param name="globalProperties">Optional <see cref="IDictionary{String, String}"/> containing global properties.</param>
        /// <param name="toolsVersion">Optional tools version.</param>
        /// <param name="projectCollection">Optional <see cref="ProjectCollection"/> to use.  Defaults to <code>ProjectCollection.GlobalProjectCollection</code>.</param>
        /// <param name="projectLoadSettings">Optional <see cref="ProjectLoadSettings"/> to use.  Defaults to <see cref="ProjectLoadSettings.Default"/>.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        public ProjectCreator TryGetProject(
            out Project project,
            IDictionary <string, string> globalProperties = null,
            string toolsVersion = null,
            ProjectCollection projectCollection     = null,
            ProjectLoadSettings projectLoadSettings = ProjectLoadSettings.Default)
        {
            project = new Project(
                RootElement,
                globalProperties,
                toolsVersion,
                projectCollection ?? ProjectCollection.GlobalProjectCollection,
                projectLoadSettings);

            return(this);
        }
コード例 #12
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        private BuildParameters(BuildParameters other)
        {
            ErrorUtilities.VerifyThrowInternalNull(other, "other");

            _buildId                 = other._buildId;
            _culture                 = other._culture;
            _defaultToolsVersion     = other._defaultToolsVersion;
            _enableNodeReuse         = other._enableNodeReuse;
            _buildProcessEnvironment = other._buildProcessEnvironment != null ? new Dictionary <string, string>(other._buildProcessEnvironment) : null;
            _environmentProperties   = other._environmentProperties != null ? new PropertyDictionary <ProjectPropertyInstance>(other._environmentProperties) : null;
            _forwardingLoggers       = other._forwardingLoggers != null ? new List <ForwardingLoggerRecord>(other._forwardingLoggers) : null;
            _globalProperties        = other._globalProperties != null ? new PropertyDictionary <ProjectPropertyInstance>(other._globalProperties) : null;
            _hostServices            = other._hostServices;
            _loggers                 = other._loggers != null ? new List <ILogger>(other._loggers) : null;
            _maxNodeCount            = other._maxNodeCount;
            _memoryUseLimit          = other._memoryUseLimit;
            _nodeExeLocation         = other._nodeExeLocation;
            _nodeId = other._nodeId;
            _onlyLogCriticalEvents = other._onlyLogCriticalEvents;
#if FEATURE_THREAD_PRIORITY
            _buildThreadPriority = other._buildThreadPriority;
#endif
            _toolsetProvider            = other._toolsetProvider;
            _toolsetDefinitionLocations = other._toolsetDefinitionLocations;
            _toolsetProvider            = other._toolsetProvider;
            _uiCulture       = other._uiCulture;
            _detailedSummary = other._detailedSummary;
            _shutdownInProcNodeOnBuildFinish = other._shutdownInProcNodeOnBuildFinish;
            this.ProjectRootElementCache     = other.ProjectRootElementCache;
            this.ResetCaches = other.ResetCaches;
            this.LegacyThreadingSemantics = other.LegacyThreadingSemantics;
            _saveOperatingEnvironment     = other._saveOperatingEnvironment;
            _useSynchronousLogging        = other._useSynchronousLogging;
            _disableInProcNode            = other._disableInProcNode;
            _logTaskInputs = other._logTaskInputs;
            _logInitialPropertiesAndItems = other._logInitialPropertiesAndItems;
            _warningsAsErrors             = other._warningsAsErrors == null ? null : new HashSet <string>(other._warningsAsErrors, StringComparer.OrdinalIgnoreCase);
            _warningsAsMessages           = other._warningsAsMessages == null ? null : new HashSet <string>(other._warningsAsMessages, StringComparer.OrdinalIgnoreCase);
            _projectLoadSettings          = other._projectLoadSettings;
        }
コード例 #13
0
        /// <summary>
        /// Gets a <see cref="Project"/> instance from the current project.
        /// </summary>
        /// <param name="project">Receives the <see cref="Project"/> instance.</param>
        /// <param name="buildOutput">Receives <see cref="BuildOutput"/> instance.</param>
        /// <param name="globalProperties">Optional <see cref="IDictionary{String, String}"/> containing global properties.</param>
        /// <param name="toolsVersion">Optional tools version.</param>
        /// <param name="projectCollection">Optional <see cref="ProjectCollection"/> to use.  Defaults to <code>ProjectCollection.GlobalProjectCollection</code>.</param>
        /// <param name="projectLoadSettings">Optional <see cref="ProjectLoadSettings"/> to use.  Defaults to <see cref="ProjectLoadSettings.Default"/>.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        public ProjectCreator TryGetProject(
            out Project project,
            out BuildOutput buildOutput,
            IDictionary <string, string> globalProperties = null,
            string toolsVersion = null,
            ProjectCollection projectCollection     = null,
            ProjectLoadSettings projectLoadSettings = ProjectLoadSettings.Default)
        {
            buildOutput = BuildOutput.Create();

            projectCollection = projectCollection ?? new ProjectCollection();

            projectCollection.RegisterLogger(buildOutput);

            project = new Project(
                RootElement,
                globalProperties,
                toolsVersion,
                projectCollection,
                projectLoadSettings);

            return(this);
        }
コード例 #14
0
ファイル: Project.cs プロジェクト: nikson/msbuild
        /// <summary>
        /// Reads in the contents of this project from a project XML file on disk.
        /// </summary>
        /// <exception cref="InvalidProjectFileException"></exception>
        internal void Load
        (
            string projectFileName,
            BuildEventContext buildEventContext,
            ProjectLoadSettings projectLoadSettings
        )
        {
            ErrorUtilities.VerifyThrowArgumentNull(projectFileName, "projectFileName");
            ErrorUtilities.VerifyThrowArgument(projectFileName.Length > 0, "EmptyProjectFileName");
            ErrorUtilities.VerifyThrowArgument(File.Exists(projectFileName), "ProjectFileNotFound", projectFileName);

#if (!STANDALONEBUILD)
            using (new CodeMarkerStartEnd(CodeMarkerEvent.perfMSBuildProjectLoadFromFileBegin, CodeMarkerEvent.perfMSBuildProjectLoadFromFileEnd))
#endif
            {
                string projectFullFileName = Path.GetFullPath(projectFileName);

                try
                {
#if MSBUILDENABLEVSPROFILING 
                string beginProjectLoad = String.Format(CultureInfo.CurrentCulture, "Load Project {0} Using Old OM - Start", projectFullFileName);
                DataCollection.CommentMarkProfile(8806, beginProjectLoad);
#endif
                    XmlDocument projectDocument = null;
                    if (IsSolutionFilename(projectFileName))
                    {
                        SolutionParser sp = new SolutionParser();

                        sp.SolutionFile = projectFileName;
                        sp.ParseSolutionFile();

                        // Log any comments from the solution parser
                        if (sp.SolutionParserComments.Count > 0)
                        {
                            foreach (string comment in sp.SolutionParserComments)
                            {
                                ParentEngine.LoggingServices.LogCommentFromText(buildEventContext, MessageImportance.Low, comment);
                            }
                        }

                        // Pass the toolsVersion of this project through, which will be not null if there was a /tv:nn switch
                        // Although we only get an XmlDocument, not a Project object back, it's still needed
                        // to determine which <UsingTask> tags to put in, whether to put a ToolsVersion parameter
                        // on <MSBuild> task tags, and what MSBuildToolsPath to use when scanning child projects
                        // for dependency information.
                        SolutionWrapperProject.Generate(sp, this, toolsVersion, buildEventContext);

                    }
                    else if (IsVCProjFilename(projectFileName))
                    {
                        ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(false, new BuildEventFileInfo(projectFileName), "ProjectUpgradeNeededToVcxProj", projectFileName);
                    }
                    else
                    {
                        projectDocument = new XmlDocument();
                        // XmlDocument.Load() may throw an XmlException
                        projectDocument.Load(projectFileName);
                    }

                    // Setting the FullFileName causes this project to be "registered" with
                    // the engine.  (Well, okay, "registered" is the wrong word ... but the
                    // engine starts keeping close track of this project in its tables.)
                    // We want to avoid this until we're sure that the XML is valid and
                    // the document can be read in.  Bug VSWhidbey 415236.
                    this.FullFileName = projectFullFileName;

                    if (!IsSolutionFilename(projectFileName))
                    {
                        InternalLoadFromXmlDocument(projectDocument, projectLoadSettings);
                    }


                    // This project just came off the disk, so it is certainly not dirty yet.
                    this.dirtyNeedToSaveProjectFile = false;
                }
                // handle errors in project syntax
                catch (InvalidProjectFileException e)
                {
                    ParentEngine.LoggingServices.LogInvalidProjectFileError(buildEventContext, e);
                    throw;
                }
                // handle errors in path resolution
                catch (SecurityException e)
                {
                    ParentEngine.LoggingServices.LogError(buildEventContext, new BuildEventFileInfo(FullFileName), "InvalidProjectFile", e.Message);

                    ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(false, new BuildEventFileInfo(FullFileName),
                        "InvalidProjectFile", e.Message);
                }
                // handle errors in path resolution
                catch (NotSupportedException e)
                {
                    ParentEngine.LoggingServices.LogError(buildEventContext, new BuildEventFileInfo(FullFileName), "InvalidProjectFile", e.Message);

                    ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(false, new BuildEventFileInfo(FullFileName),
                        "InvalidProjectFile", e.Message);
                }
                // handle errors in loading project file
                catch (IOException e)
                {
                    ParentEngine.LoggingServices.LogError(buildEventContext, new BuildEventFileInfo(FullFileName), "InvalidProjectFile", e.Message);

                    ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(false, new BuildEventFileInfo(FullFileName),
                        "InvalidProjectFile", e.Message);
                }
                // handle errors in loading project file
                catch (UnauthorizedAccessException e)
                {
                    ParentEngine.LoggingServices.LogError(buildEventContext, new BuildEventFileInfo(FullFileName), "InvalidProjectFile", e.Message);
                    ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(false, new BuildEventFileInfo(FullFileName),
                        "InvalidProjectFile", e.Message);
                }
                // handle XML parsing errors (when reading project file)
                catch (XmlException e)
                {
                    BuildEventFileInfo fileInfo = new BuildEventFileInfo(e);

                    ParentEngine.LoggingServices.LogError(buildEventContext, fileInfo, "InvalidProjectFile", e.Message);

                    ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(false, fileInfo,
                        "InvalidProjectFile", e.Message);
                }
                finally
                {
                    // Flush the logging queue
                    ParentEngine.LoggingServices.ProcessPostedLoggingEvents();
#if MSBUILDENABLEVSPROFILING 
                DataCollection.CommentMarkProfile(8807, "Load Project Using Old OM - End");
#endif
                }
            }
        }
コード例 #15
0
ファイル: Project.cs プロジェクト: nikson/msbuild
 /// <summary>
 /// Reads in the contents of this project from a project XML file on disk.
 /// </summary>
 /// <exception cref="InvalidProjectFileException"></exception>
 public void Load
 (
     string projectFileName,
     ProjectLoadSettings projectLoadSettings
 )
 {
     Load(projectFileName, projectBuildEventContext, projectLoadSettings);
 }
コード例 #16
0
 /// <summary>
 /// Loads a single project if it hasn't already been loaded.
 /// </summary>
 /// <param name="projectPath">The path to the project.</param>
 /// <param name="projectCollection">A <see cref="ProjectCollection"/> to load the project into.</param>
 /// <param name="projectLoadSettings">Specifies the <see cref="ProjectLoadSettings"/> to use when loading projects.</param>
 private void LoadProject(string projectPath, ProjectCollection projectCollection, ProjectLoadSettings projectLoadSettings)
 {
     if (TryLoadProject(projectPath, projectCollection.DefaultToolsVersion, projectCollection, projectLoadSettings, out Project project))
     {
         LoadProjectReferences(project, _projectLoadSettings);
     }
 }
コード例 #17
0
        /// <summary>
        /// Attempts to load the specified project if it hasn't already been loaded.
        /// </summary>
        /// <param name="path">The path to the project to load.</param>
        /// <param name="toolsVersion">The ToolsVersion to use when loading the project.</param>
        /// <param name="projectCollection">The <see cref="ProjectCollection"/> to load the project into.</param>
        /// <param name="projectLoadSettings">Specifies the <see cref="ProjectLoadSettings"/> to use when loading projects.</param>
        /// <param name="project">Contains the loaded <see cref="Project"/> if one was loaded.</param>
        /// <returns><code>true</code> if the project was loaded, otherwise <code>false</code>.</returns>
        private bool TryLoadProject(string path, string toolsVersion, ProjectCollection projectCollection, ProjectLoadSettings projectLoadSettings, out Project project)
        {
            project = null;

            bool shouldLoadProject;

            string fullPath = path.ToFullPathInCorrectCase();

            lock (_loadedProjects)
            {
                shouldLoadProject = _loadedProjects.Add(fullPath);
            }

            if (!shouldLoadProject)
            {
                return(false);
            }

            long now = DateTime.Now.Ticks;

            try
            {
                project = new Project(fullPath, null, toolsVersion, projectCollection, projectLoadSettings);
            }
            catch (InvalidProjectFileException e)
            {
                _buildEngine.LogErrorEvent(new BuildErrorEventArgs(
                                               subcategory: null,
                                               code: e.ErrorCode,
                                               file: e.ProjectFile,
                                               lineNumber: e.LineNumber,
                                               columnNumber: e.ColumnNumber,
                                               endLineNumber: e.EndLineNumber,
                                               endColumnNumber: e.EndColumnNumber,
                                               message: e.Message,
                                               helpKeyword: e.HelpKeyword,
                                               senderName: null));

                return(false);
            }
            catch (Exception e)
            {
                _buildEngine.LogErrorEvent(new BuildErrorEventArgs(
                                               subcategory: null,
                                               code: null,
                                               file: path,
                                               lineNumber: 0,
                                               columnNumber: 0,
                                               endLineNumber: 0,
                                               endColumnNumber: 0,
                                               message: e.ToString(),
                                               helpKeyword: null,
                                               senderName: null));

                return(false);
            }

            if (CollectStats)
            {
                Statistics.TryAddProjectLoadTime(path, TimeSpan.FromTicks(DateTime.Now.Ticks - now));
            }

            return(true);
        }
コード例 #18
0
 public Project LoadProjectWithSettings(string path, ProjectLoadSettings settings) => new Project(path, null, null, this.Collection, settings);
コード例 #19
0
ファイル: Project.cs プロジェクト: nikson/msbuild
        /// <summary>
        /// Reads in the contents of this project from a string containing the Xml contents.
        /// </summary>
        /// <exception cref="InvalidProjectFileException"></exception>
        public void LoadXml
        (
            string projectXml,
            ProjectLoadSettings projectLoadSettings
        )
        {
            ErrorUtilities.VerifyThrowArgumentNull(projectXml, "projectXml");

            try
            {
                XmlDocument projectDocument = new XmlDocument();
                // XmlDocument.Load() may throw an XmlException
                projectDocument.LoadXml(projectXml);

                InternalLoadFromXmlDocument(projectDocument, projectLoadSettings);

                // This means that as far as we know, this project hasn't been saved to disk yet.
                this.dirtyNeedToSaveProjectFile = true;
            }
            // handle errors in project syntax
            catch (InvalidProjectFileException e)
            {
                ParentEngine.LoggingServices.LogInvalidProjectFileError(projectBuildEventContext, e);
                throw;
            }
            // handle XML parsing errors (when reading XML contents)
            catch (XmlException e)
            {
                BuildEventFileInfo fileInfo = new BuildEventFileInfo(e);

                ParentEngine.LoggingServices.LogError(projectBuildEventContext, null,fileInfo, "InvalidProjectFile", e.Message);

                ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(false, fileInfo,
                    "InvalidProjectFile", e.Message);
            }
        }
コード例 #20
0
ファイル: Project.cs プロジェクト: pmq20/mono_forked
 public Project(string projectFile, IDictionary <string, string> globalProperties,
                string toolsVersion, ProjectCollection projectCollection,
                ProjectLoadSettings loadSettings)
     : this(ProjectRootElement.Create(projectFile), globalProperties, toolsVersion, projectCollection, loadSettings)
 {
 }
コード例 #21
0
 public Project (string projectFile, IDictionary<string, string> globalProperties,
                 string toolsVersion, ProjectCollection projectCollection,
                 ProjectLoadSettings loadSettings)
 {
         throw new NotImplementedException ();
 }
コード例 #22
0
ファイル: ObjectModelHelpers.cs プロジェクト: 3F/IeXod
        /// <summary>
        /// Create an in-memory project and attach it to the passed-in engine.
        /// </summary>
        /// <param name="logger">May be null</param>
        /// <param name="toolsVersion">May be null</param>
        static internal Project CreateInMemoryProject(Engine e, string xml, ILogger logger /* May be null */, string toolsVersion /* may be null */, ProjectLoadSettings projectLoadSettings)
        {
            // Anonymous in-memory projects use the current directory for $(MSBuildProjectDirectory).
            // We need to set the directory to something reasonable.
            string originalDir = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));

#if _NEVER
            // Attach a console logger so that build output can go to the test
            // harness.
            e.RegisterLogger(new ConsoleLogger(ConsoleLogger.Verbosity.Verbose));
#endif

            Project p = new Project(e, toolsVersion);
            p.FullFileName = Path.Combine(Path.GetTempPath(), "Temporary.csproj");

            if (logger != null)
            {
                p.ParentEngine.RegisterLogger(logger);
            }
            p.LoadXml(CleanupFileContents(xml), projectLoadSettings);

            // Return to the original directory.
            Directory.SetCurrentDirectory(originalDir);

            return(p);
        }
コード例 #23
0
ファイル: Project.cs プロジェクト: nikson/msbuild
        /// <summary>
        /// Reads in the contents of this project from an in-memory XmlDocument handed to us.
        /// </summary>
        /// <exception cref="InvalidProjectFileException"></exception>
        internal void LoadFromXmlDocument
            (
            XmlDocument projectXml,
            BuildEventContext buildEventContext,
            ProjectLoadSettings projectLoadSettings
            )
        {
            ErrorUtilities.VerifyThrowArgumentNull(projectXml, "projectXml");

            try
            {
                InternalLoadFromXmlDocument(projectXml, projectLoadSettings);
            }
            // handle errors in project syntax
            catch (InvalidProjectFileException e)
            {
                ParentEngine.LoggingServices.LogInvalidProjectFileError(buildEventContext, e);
                throw;
            }
        }
コード例 #24
0
ファイル: Project.cs プロジェクト: nikson/msbuild
        /// <summary>
        /// Reads in the contents of this project from an in-memory XmlDocument.
        /// </summary>
        /// <remarks>This method throws exceptions -- it is the responsibility of the caller to handle them.</remarks>
        /// <exception cref="InvalidProjectFileException"></exception>
        private void InternalLoadFromXmlDocument(XmlDocument projectXml, ProjectLoadSettings projectLoadSettings)
        {
            try
            {
                ErrorUtilities.VerifyThrow(projectXml != null, "Need project XML.");

                this.loadSettings = projectLoadSettings;
                this.mainProjectEntireContents = projectXml;

                // Get the top-level nodes from the XML.
                XmlNodeList projectFileNodes = mainProjectEntireContents.ChildNodes;

                // The XML parser will guarantee that we only have one real root element,
                // but we need to find it amongst the other types of XmlNode at the root.
                foreach (XmlNode childNode in projectFileNodes)
                {
                    if (XmlUtilities.IsXmlRootElement(childNode))
                    {
                        this.mainProjectElement = (XmlElement)childNode;
                        break;
                    }
                }

                // Verify that we found a non-comment root node
                ProjectErrorUtilities.VerifyThrowInvalidProject(this.mainProjectElement != null,
                    this.mainProjectEntireContents,
                    "NoRootProjectElement", XMakeElements.project);

                // If we have a <VisualStudioProject> node, tell the user they must upgrade the project
                ProjectErrorUtilities.VerifyThrowInvalidProject(mainProjectElement.LocalName != XMakeElements.visualStudioProject,
                    mainProjectElement, "ProjectUpgradeNeeded");

                // This node must be a <Project> node.
                ProjectErrorUtilities.VerifyThrowInvalidProject(this.mainProjectElement.LocalName == XMakeElements.project,
                    this.mainProjectElement, "UnrecognizedElement", this.mainProjectElement.Name);

                ProjectErrorUtilities.VerifyThrowInvalidProject((mainProjectElement.Prefix.Length == 0) && (String.Compare(mainProjectElement.NamespaceURI, XMakeAttributes.defaultXmlNamespace, StringComparison.OrdinalIgnoreCase) == 0),
                    mainProjectElement, "ProjectMustBeInMSBuildXmlNamespace", XMakeAttributes.defaultXmlNamespace);

                MarkProjectAsDirtyForReprocessXml();
                this.RefreshProjectIfDirty();
            }
            catch (InvalidProjectFileException)
            {
                // Make sure the engine doesn't keep bad projects around
                if (this.IsLoadedByHost)
                {
                    Engine rememberParentEngine = this.ParentEngine;
                    this.ParentEngine.UnloadProject(this);
                    this.parentEngine = rememberParentEngine;
                }
                throw;
            }

        }
コード例 #25
0
        public void GetImportPathsAndImportPathsIncludingDuplicates(bool useDirectConstruction, ProjectLoadSettings projectLoadSettings)
        {
            try
            {
                string projectFileContent = @"
                    <Project>
                        <Import Project='{0}'/>
                        <Import Project='{1}'/>
                        <Import Project='{0}'/>
                    </Project>";

                string import1Content = @"
                    <Project>
                        <Import Project='{0}'/>
                        <Import Project='{1}'/>
                    </Project>";

                string import2Content = @"<Project />";
                string import3Content = @"<Project />";

                string import2Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("import2.targets", import2Content);
                string import3Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("import3.targets", import3Content);

                import1Content = string.Format(import1Content, import2Path, import3Path);
                string import1Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("import1.targets", import1Content);

                projectFileContent = string.Format(projectFileContent, import1Path, import2Path);

                ProjectCollection projectCollection = new ProjectCollection();
                BuildParameters   buildParameters   = new BuildParameters(projectCollection)
                {
                    ProjectLoadSettings = projectLoadSettings
                };
                BuildEventContext buildEventContext = new BuildEventContext(0, BuildEventContext.InvalidTargetId, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidTaskId);

                ProjectRootElement rootElement     = ProjectRootElement.Create(XmlReader.Create(new StringReader(projectFileContent)));
                ProjectInstance    projectInstance = useDirectConstruction
                    ? new ProjectInstance(rootElement, globalProperties: null, toolsVersion: null, buildParameters, projectCollection.LoggingService, buildEventContext, sdkResolverService: null, 0)
                    : new Project(rootElement, globalProperties: null, toolsVersion: null, projectCollection, projectLoadSettings).CreateProjectInstance();

                string[] expectedImportPaths = new string[] { import1Path, import2Path, import3Path };
                string[] expectedImportPathsIncludingDuplicates = projectLoadSettings.HasFlag(ProjectLoadSettings.RecordDuplicateButNotCircularImports)
                    ? new string[] { import1Path, import2Path, import3Path, import2Path, import1Path }
                    : expectedImportPaths;

                Helpers.AssertListsValueEqual(expectedImportPaths, projectInstance.ImportPaths.ToList());
                Helpers.AssertListsValueEqual(expectedImportPathsIncludingDuplicates, projectInstance.ImportPathsIncludingDuplicates.ToList());
            }
            finally
            {
                ObjectModelHelpers.DeleteTempProjectDirectory();
            }
        }
コード例 #26
0
ファイル: Project.cs プロジェクト: symform/mono
                public Project (XmlReader xml, IDictionary<string, string> globalProperties,
                                string toolsVersion, ProjectCollection projectCollection,
                                ProjectLoadSettings loadSettings)
			: this (ProjectRootElement.Create (xml), globalProperties, toolsVersion, projectCollection, loadSettings)
		{
		}
コード例 #27
0
 public Project(string projectFile, IDictionary <string, string> globalProperties,
                string toolsVersion, ProjectCollection projectCollection,
                ProjectLoadSettings loadSettings)
 {
     throw new NotImplementedException();
 }
コード例 #28
0
ファイル: Project.cs プロジェクト: pmq20/mono_forked
 public Project(XmlReader xml, IDictionary <string, string> globalProperties,
                string toolsVersion, ProjectCollection projectCollection,
                ProjectLoadSettings loadSettings)
     : this(ProjectRootElement.Create(xml), globalProperties, toolsVersion, projectCollection, loadSettings)
 {
 }
コード例 #29
0
        /// <summary>
        /// Attempts to load the specified project if it hasn't already been loaded.
        /// </summary>
        /// <param name="path">The path to the project to load.</param>
        /// <param name="toolsVersion">The ToolsVersion to use when loading the project.</param>
        /// <param name="projectCollection">The <see cref="ProjectCollection"/> to load the project into.</param>
        /// <param name="projectLoadSettings">Specifies the <see cref="ProjectLoadSettings"/> to use when loading projects.</param>
        /// <param name="project">Contains the loaded <see cref="Project"/> if one was loaded.</param>
        /// <returns><code>true</code> if the project was loaded, otherwise <code>false</code>.</returns>
        private bool TryLoadProject(string path, string toolsVersion, ProjectCollection projectCollection, ProjectLoadSettings projectLoadSettings, out Project project)
        {
            project = null;

            bool shouldLoadProject;

            lock (_loadedProjects)
            {
                shouldLoadProject = _loadedProjects.Add(Path.GetFullPath(path));
            }

            if (!shouldLoadProject)
            {
                return(false);
            }

            long now = DateTime.Now.Ticks;

            try
            {
                project = new Project(path, null, toolsVersion, projectCollection, projectLoadSettings);
            }
            catch (InvalidProjectFileException e)
            {
                _log.LogError(null, e.ErrorCode, e.HelpKeyword, e.ProjectFile, e.LineNumber, e.ColumnNumber, e.EndLineNumber, e.EndColumnNumber, e.Message);
                return(false);
            }
            catch (Exception e)
            {
                _log.LogError(null, null, null, path, 0, 0, 0, 0, e.ToString());
                return(false);
            }

            if (CollectStats)
            {
                Statistics.TryAddProjectLoadTime(path, TimeSpan.FromTicks(DateTime.Now.Ticks - now));
            }

            return(true);
        }
コード例 #30
0
ファイル: ObjectModelHelpers.cs プロジェクト: nikson/msbuild
        /// <summary>
        /// Create an in-memory project and attach it to the passed-in engine.
        /// </summary>
        /// <param name="logger">May be null</param>
        /// <param name="toolsVersion">May be null</param>
        static internal Project CreateInMemoryProject(Engine e, string xml, ILogger logger /* May be null */, string toolsVersion/* may be null */, ProjectLoadSettings projectLoadSettings)
        {
            // Anonymous in-memory projects use the current directory for $(MSBuildProjectDirectory).
            // We need to set the directory to something reasonable.
            string originalDir = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));

#if _NEVER
            // Attach a console logger so that build output can go to the test
            // harness.
            e.RegisterLogger(new ConsoleLogger(ConsoleLogger.Verbosity.Verbose));
#endif

            Project p = new Project(e, toolsVersion);
            p.FullFileName = Path.Combine(Path.GetTempPath(), "Temporary.csproj");

            if (logger != null)
            {
                p.ParentEngine.RegisterLogger(logger);
            }
            p.LoadXml(CleanupFileContents(xml), projectLoadSettings);

            // Return to the original directory.
            Directory.SetCurrentDirectory(originalDir);

            return p;   
        }