Ejemplo n.º 1
0
        public void Evaluate()
        {
            if (projectInstance != null)
            {
                engine.DisposeProjectInstance(projectInstance);
            }

            info = msproject.LoadNativeInstance();

            engine          = info.Engine;
            projectInstance = engine.CreateProjectInstance(info.Project);

            try {
                foreach (var prop in globalProperties)
                {
                    engine.SetGlobalProperty(projectInstance, prop.Key, prop.Value);
                }

                engine.Evaluate(projectInstance);

                SyncBuildProject(info.ItemMap, info.Engine, projectInstance);
            } catch (Exception ex) {
                // If the project can't be evaluated don't crash
                LoggingService.LogError("MSBuild project could not be evaluated", ex);
                throw new ProjectEvaluationException(msproject, ex.Message);
            }
        }
Ejemplo n.º 2
0
        internal MSBuildProjectInstanceInfo LoadNativeInstance()
        {
            lock (readLock) {
                var supportsMSBuild = UseMSBuildEngine && GetGlobalPropertyGroup().GetValue("UseMSBuildEngine", true);

                if (engineManager == null)
                {
                    engineManager        = new MSBuildEngineManager();
                    engineManagerIsLocal = true;
                }

                MSBuildEngine e = engineManager.GetEngine(supportsMSBuild);

                if (nativeProjectInfo != null && nativeProjectInfo.Engine != null && (nativeProjectInfo.Engine != e || nativeProjectInfo.ProjectStamp != ChangeStamp))
                {
                    nativeProjectInfo.Engine.UnloadProject(nativeProjectInfo.Project);
                    nativeProjectInfo = null;
                }

                if (nativeProjectInfo == null)
                {
                    nativeProjectInfo = new MSBuildProjectInstanceInfo {
                        Engine       = e,
                        ProjectStamp = ChangeStamp
                    };
                }

                if (nativeProjectInfo.Project == null)
                {
                    // Use a private metadata property to assign an id to each item. This id is used to match
                    // evaluated items with the items that generated them.

                    try {
                        DisableChangeTracking();

                        var ctx = new WriteContext {
                            Evaluating = true,
                            ItemMap    = new Dictionary <string, MSBuildItem> ()
                        };
                        var xml = SaveToString(ctx);

                        foreach (var it in GetAllItems())
                        {
                            it.EvaluatedItemCount = 0;
                        }

                        nativeProjectInfo.Project = e.LoadProject(this, xml, FileName);
                    } catch (Exception ex) {
                        // If the project can't be evaluated don't crash
                        LoggingService.LogError("MSBuild project could not be evaluated", ex);
                        throw new ProjectEvaluationException(this, ex.Message);
                    } finally {
                        EnableChangeTracking();
                    }
                }
                return(nativeProjectInfo);
            }
        }
Ejemplo n.º 3
0
        public void Evaluate()
        {
            object oldProjectInstance = null;

            if (projectInstance != null)
            {
                oldProjectInstance = projectInstance;
            }

            info = msproject.LoadNativeInstance(!OnlyEvaluateProperties);

            engine          = info.Engine;
            projectInstance = engine.CreateProjectInstance(info.Project);

            try {
                // Set properties defined by global property providers, and then
                // properties explicitly set to this instance

                foreach (var gpp in MSBuildProjectService.GlobalPropertyProviders)
                {
                    foreach (var prop in gpp.GetGlobalProperties())
                    {
                        engine.SetGlobalProperty(projectInstance, prop.Key, prop.Value);
                    }
                }
                foreach (var prop in globalProperties)
                {
                    engine.SetGlobalProperty(projectInstance, prop.Key, prop.Value);
                }

                engine.Evaluate(projectInstance, OnlyEvaluateProperties);

                SyncBuildProject(info.ItemMap, info.Engine, projectInstance);
            } catch (UserException ex) {
                LoggingService.LogError("MSBuild project could not be evaluated", ex);
                throw;
            } catch (Exception ex) {
                // If the project can't be evaluated don't crash
                LoggingService.LogError("MSBuild project could not be evaluated", ex);
                throw new ProjectEvaluationException(msproject, ex.Message);
            } finally {
                if (oldProjectInstance != null)
                {
                    engine.DisposeProjectInstance(oldProjectInstance);
                }
            }
        }
Ejemplo n.º 4
0
 void DisposeMainInstance()
 {
     if (nativeProjectInfo != null)
     {
         if (mainProjectInstance != null)
         {
             mainProjectInstance.Dispose();
         }
         nativeProjectInfo.Engine.UnloadProject(nativeProjectInfo.Project);
         if (engineManagerIsLocal)
         {
             nativeProjectInfo.Engine.Dispose();
         }
         nativeProjectInfo   = null;
         mainProjectInstance = null;
     }
 }
Ejemplo n.º 5
0
		internal MSBuildProjectInstanceInfo LoadNativeInstance ()
		{
			lock (readLock) {
				var supportsMSBuild = UseMSBuildEngine && GetGlobalPropertyGroup ().GetValue ("UseMSBuildEngine", true);

				if (engineManager == null) {
					engineManager = new MSBuildEngineManager ();
					engineManagerIsLocal = true;
				}

				MSBuildEngine e = engineManager.GetEngine (supportsMSBuild);

				if (nativeProjectInfo != null && nativeProjectInfo.Engine != null && (nativeProjectInfo.Engine != e || nativeProjectInfo.ProjectStamp != ChangeStamp)) {
					nativeProjectInfo.Engine.UnloadProject (nativeProjectInfo.Project);
					nativeProjectInfo = null;
				}

				if (nativeProjectInfo == null) {
					nativeProjectInfo = new MSBuildProjectInstanceInfo {
						Engine = e,
						ProjectStamp = ChangeStamp
					};
				}

				if (nativeProjectInfo.Project == null) {
					// Use a private metadata property to assign an id to each item. This id is used to match
					// evaluated items with the items that generated them.

					try {
						DisableChangeTracking ();

						var ctx = new WriteContext {
							Evaluating = true,
							ItemMap = new Dictionary<string, MSBuildItem> ()
						};
						var xml = SaveToString (ctx);

						foreach (var it in GetAllItems ())
							it.EvaluatedItemCount = 0;

						nativeProjectInfo.Project = e.LoadProject (this, xml, FileName);
					} catch (Exception ex) {
						// If the project can't be evaluated don't crash
						LoggingService.LogError ("MSBuild project could not be evaluated", ex);
						throw new ProjectEvaluationException (this, ex.Message);
					} finally {
						EnableChangeTracking ();
					}
				}
				return nativeProjectInfo;
			}
		}
Ejemplo n.º 6
0
		void DisposeMainInstance ()
		{
			if (nativeProjectInfo != null) {
				if (mainProjectInstance != null)
					mainProjectInstance.Dispose ();
				nativeProjectInfo.Engine.UnloadProject (nativeProjectInfo.Project);
				if (engineManagerIsLocal)
					nativeProjectInfo.Engine.Dispose ();
				nativeProjectInfo = null;
				mainProjectInstance = null;
			}
		}
		public void Evaluate ()
		{
			if (projectInstance != null)
				engine.DisposeProjectInstance (projectInstance);

			info = msproject.LoadNativeInstance ();

			engine = info.Engine;
			projectInstance = engine.CreateProjectInstance (info.Project);

			try {
				foreach (var prop in globalProperties)
					engine.SetGlobalProperty (projectInstance, prop.Key, prop.Value);

				engine.Evaluate (projectInstance);

				SyncBuildProject (info.ItemMap, info.Engine, projectInstance);
			} catch (Exception ex) {
				// If the project can't be evaluated don't crash
				LoggingService.LogError ("MSBuild project could not be evaluated", ex);
				throw new ProjectEvaluationException (msproject, ex.Message);
			}
		}