internal static MSBuild.Project LoadProject(MSBuild.ProjectCollection buildEngine, string fullProjectPath) { var buildProject = buildEngine.GetLoadedProjects(fullProjectPath).FirstOrDefault(); if (buildProject != null) { buildEngine.UnloadProject(buildProject); } return buildEngine.LoadProject(fullProjectPath); }
/// <summary> /// Initializes the in memory project. Sets BuildEnabled on the project to true. /// </summary> /// <param name="engine">The build engine to use to create a build project.</param> /// <param name="fullProjectPath">The full path of the project.</param> /// <returns>A loaded msbuild project.</returns> internal static MSBuild.Project InitializeMsBuildProject(MSBuild.ProjectCollection buildEngine, string fullProjectPath) { Utilities.ArgumentNotNullOrEmpty("fullProjectPath", fullProjectPath); // Call GetFullPath to expand any relative path passed into this method. fullProjectPath = CommonUtils.NormalizePath(fullProjectPath); // Check if the project already has been loaded with the fullProjectPath. If yes return the build project associated to it. List<MSBuild.Project> loadedProject = new List<MSBuild.Project>(buildEngine.GetLoadedProjects(fullProjectPath)); MSBuild.Project buildProject = loadedProject != null && loadedProject.Count > 0 && loadedProject[0] != null ? loadedProject[0] : null; if (buildProject == null) { buildProject = buildEngine.LoadProject(fullProjectPath); } return buildProject; }