Project ConfigureProject(string file, string configuration, string platform, string slnConfigContents) { var p = engine.GetLoadedProjects(file).FirstOrDefault(); if (p == null) { var content = buildEngine.GetUnsavedProjectContent(file); if (content == null) { p = engine.LoadProject(file); } else { Environment.CurrentDirectory = Path.GetDirectoryName(file); p = engine.LoadProject(new XmlTextReader(new StringReader(content))); p.FullPath = file; } } p.SetProperty("CurrentSolutionConfigurationContents", slnConfigContents); p.SetProperty("Configuration", configuration); if (!string.IsNullOrEmpty(platform)) { p.SetProperty("Platform", platform); } else { p.SetProperty("Platform", ""); } return(p); }
Project ConfigureProject(string file, string configuration, string platform, string slnConfigContents) { var p = engine.GetLoadedProjects(file).FirstOrDefault(); if (p == null) { var projectDir = Path.GetDirectoryName(file); // HACK: workaround to MSBuild bug #53019. We need to ensure that $(BaseIntermediateOutputPath) exists before // loading the project. if (!string.IsNullOrEmpty(projectDir)) { Directory.CreateDirectory(Path.Combine(projectDir, "obj")); } var content = buildEngine.GetUnsavedProjectContent(file); if (content == null) { p = engine.LoadProject(file); } else { if (!string.IsNullOrEmpty(projectDir) && Directory.Exists(projectDir)) { Environment.CurrentDirectory = projectDir; } var projectRootElement = ProjectRootElement.Create(new XmlTextReader(new StringReader(content))); projectRootElement.FullPath = file; // Use the engine's default tools version to load the project. We want to build with the latest // tools version. string toolsVersion = engine.DefaultToolsVersion; p = new Project(projectRootElement, engine.GlobalProperties, toolsVersion, engine); } } p.SetGlobalProperty("CurrentSolutionConfigurationContents", slnConfigContents); p.SetGlobalProperty("Configuration", configuration); if (!string.IsNullOrEmpty(platform)) { p.SetGlobalProperty("Platform", platform); } else { p.RemoveGlobalProperty("Platform"); } p.ReevaluateIfNecessary(); return(p); }
Project SetupProject(ProjectConfigurationInfo[] configurations) { Project project = null; var slnConfigContents = GenerateSolutionConfigurationContents(configurations); foreach (var pc in configurations) { var p = buildEngine.Engine.GetLoadedProject(pc.ProjectFile); if (p != null && pc.ProjectFile == file) { // building the project may create new items and/or modify some properties, // so we always need to use a new instance of the project when building buildEngine.Engine.UnloadProject(p); p = null; } Environment.CurrentDirectory = Path.GetDirectoryName(Path.GetFullPath(file)); if (p == null) { p = new Project(buildEngine.Engine); var content = buildEngine.GetUnsavedProjectContent(pc.ProjectFile); if (content == null) { p.Load(pc.ProjectFile); } else { p.FullFileName = Path.GetFullPath(pc.ProjectFile); if (HasXbuildFileBug()) { // Workaround for Xamarin bug #14295: Project.Load incorrectly resets the FullFileName property var t = p.GetType(); t.InvokeMember("PushThisFileProperty", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, p, new object[] { p.FullFileName }); t.InvokeMember("DoLoad", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, p, new object[] { new StringReader(content) }); } else { p.Load(new StringReader(content)); } } } p.GlobalProperties.SetProperty("CurrentSolutionConfigurationContents", slnConfigContents); p.GlobalProperties.SetProperty("Configuration", pc.Configuration); if (!string.IsNullOrEmpty(pc.Platform)) { p.GlobalProperties.SetProperty("Platform", pc.Platform); } else { p.GlobalProperties.RemoveProperty("Platform"); } if (pc.ProjectFile == file) { project = p; } } Environment.CurrentDirectory = Path.GetDirectoryName(Path.GetFullPath(file)); return(project); }
Project ConfigureProject(string file, string configuration, string platform, string slnConfigContents) { var p = engine.GetLoadedProjects(file).FirstOrDefault(); if (p == null) { var projectDir = Path.GetDirectoryName(file); // HACK: workaround to MSBuild bug #53019. We need to ensure that $(BaseIntermediateOutputPath) exists before // loading the project. if (!string.IsNullOrEmpty(projectDir)) { Directory.CreateDirectory(Path.Combine(projectDir, "obj")); } var content = buildEngine.GetUnsavedProjectContent(file); if (content == null) { p = engine.LoadProject(file); } else { if (!string.IsNullOrEmpty(projectDir) && Directory.Exists(projectDir)) { Environment.CurrentDirectory = projectDir; } var projectRootElement = ProjectRootElement.Create(new XmlTextReader(new StringReader(content))); projectRootElement.FullPath = file; // Use the engine's default tools version to load the project. We want to build with the latest // tools version. string toolsVersion = engine.DefaultToolsVersion; p = new Project(projectRootElement, engine.GlobalProperties, toolsVersion, engine); } } bool reevaluate = false; if (p.GetPropertyValue("Configuration") != configuration || (p.GetPropertyValue("Platform") ?? "") != (platform ?? "")) { p.SetGlobalProperty("Configuration", configuration); if (!string.IsNullOrEmpty(platform)) { p.SetGlobalProperty("Platform", platform); } else { p.RemoveGlobalProperty("Platform"); } reevaluate = true; } // The CurrentSolutionConfigurationContents property only needs to be set once // for the project actually being built // If a build session was started, that property is already set at engine level if (!buildEngine.BuildOperationStarted && this.file == file && p.GetPropertyValue("CurrentSolutionConfigurationContents") != slnConfigContents) { p.SetGlobalProperty("CurrentSolutionConfigurationContents", slnConfigContents); reevaluate = true; } if (reevaluate) { p.ReevaluateIfNecessary(); } return(p); }