Exemplo n.º 1
0
        public void ConstructWithNothing()
        {
            BuildPropertyGroup group = new BuildPropertyGroup();

            Assertion.AssertEquals(0, group.Count);
            Assertion.AssertEquals(false, group.IsImported);
        }
Exemplo n.º 2
0
		public Toolset (string toolsVersion, string toolsPath, string toolsFrameworkPath, BuildPropertyGroup buildProperties)
		{
			ToolsVersion = toolsVersion;
			ToolsPath = toolsPath;
			FrameworkToolsPath = toolsFrameworkPath;
			BuildProperties = buildProperties;
		}
Exemplo n.º 3
0
 protected override void OnSetupReleaseGroup(BuildPropertyGroup group)
 {
     group.AddNewProperty("DefineDebug", "false");
     group.AddNewProperty("DefineTrace", "true");
     group.AddNewProperty("DocumentationFile", Name + ".xml");
     group.AddNewProperty("NoWarn", "42016,41999,42017,42018,42019,42032,42036,42020,42021,42022");
 }
Exemplo n.º 4
0
        private CacheScope GetCacheScopeIfExists(string scopeName, BuildPropertyGroup scopeProperties, string scopeToolsVersion, CacheContentType cacheContentType)
        {
            CacheScope cacheScope = null;

            // Default the version to the default engine version
            if (scopeToolsVersion == null)
            {
                scopeToolsVersion = defaultToolsVersion;
            }

            // Retrieve list of scopes by this name
            if (cacheContents[(int)cacheContentType].ContainsKey(scopeName))
            {
                List<CacheScope> scopesByName = (List<CacheScope>)cacheContents[(int)cacheContentType][scopeName];

                // If the list exists search for matching scope properties otherwise create the list
                if (scopesByName != null)
                {
                    lock (cacheManagerLock)
                    {
                        for (int i = 0; i < scopesByName.Count; i++)
                        {
                            if (scopesByName[i].ScopeProperties.IsEquivalent(scopeProperties) && (String.Compare(scopeToolsVersion, scopesByName[i].ScopeToolsVersion, StringComparison.OrdinalIgnoreCase) == 0))
                            {
                                cacheScope = scopesByName[i];
                                break;
                            }
                        }
                    }
                }
            }

            return cacheScope;
        }
Exemplo n.º 5
0
		public bool BuildProjectFile (string projectFileName,
				       string[] targetNames,
				       IDictionary globalProperties,
				       IDictionary targetOutputs, string toolsVersion)
		{
			if (String.IsNullOrEmpty (projectFileName)) {
				string oldProjectToolsVersion = project.ToolsVersion;
				project.ToolsVersion = toolsVersion;
				try {
					return engine.BuildProject (project, targetNames, targetOutputs,
						BuildSettings.DoNotResetPreviouslyBuiltTargets);
				} finally {
					project.ToolsVersion = oldProjectToolsVersion;
				}
			} else {
				BuildPropertyGroup bpg = new BuildPropertyGroup ();
				if (globalProperties != null)
					foreach (DictionaryEntry de in globalProperties)
						bpg.AddProperty (new BuildProperty (
							(string) de.Key, (string) de.Value,
							PropertyType.Global));
				return engine.BuildProjectFile (projectFileName,
					targetNames, bpg, targetOutputs, BuildSettings.DoNotResetPreviouslyBuiltTargets, toolsVersion);
			}
		}
Exemplo n.º 6
0
        public void ExpandAllIntoTaskItems3()
        {
            BuildPropertyGroup pg = new BuildPropertyGroup();

            BuildItemGroup ig = new BuildItemGroup();
            ig.AddItem(new BuildItem("Compile", "foo.cs"));
            ig.AddItem(new BuildItem("Compile", "bar.cs"));

            BuildItemGroup ig2 = new BuildItemGroup();
            ig2.AddItem(new BuildItem("Resource", "bing.resx"));

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemsByType["Compile"] = ig;
            itemsByType["Resource"] = ig2;

            Expander expander = new Expander(pg, itemsByType);

            List<TaskItem> itemsOut = expander.ExpandAllIntoTaskItems("foo;bar;@(compile);@(resource)", null);

            ObjectModelHelpers.AssertItemsMatch(@"
                foo
                bar
                foo.cs
                bar.cs
                bing.resx
                ", itemsOut.ToArray());
        }
Exemplo n.º 7
0
        public void Metadata()
        {
            string content = @"
            <i Include='i1' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
               <m>$(p)</m>
               <n>n1</n>
            </i>";
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(content);
            BuildItem item = CreateBuildItemFromXmlDocument(doc);
            Assertion.AssertEquals("i", item.Name);
            BuildPropertyGroup properties = new BuildPropertyGroup();
            properties.SetProperty("p", "p1");

            // Evaluated
            Expander expander = new Expander(properties, null, ExpanderOptions.ExpandAll);
            item.EvaluateAllItemMetadata(expander, ParserOptions.AllowPropertiesAndItemLists, null, null);
            Assertion.AssertEquals("p1", item.GetEvaluatedMetadata("m"));

            // Unevaluated
            Assertion.AssertEquals("$(p)", item.GetMetadata("m"));
            Assertion.AssertEquals("n1", item.GetMetadata("n"));

            // All custom metadata
            ArrayList metadataNames = new ArrayList(item.CustomMetadataNames);
            Assertion.Assert(metadataNames.Contains("n"));
            Assertion.Assert(metadataNames.Contains("m"));

            // Custom metadata count only
            Assertion.AssertEquals(2, item.CustomMetadataCount);
            
            // All metadata count
            Assertion.AssertEquals(2 + FileUtilities.ItemSpecModifiers.All.Length, item.MetadataCount);
        }
Exemplo n.º 8
0
 public void SetUp()
 {
     // Whole bunch of setup code.
     XmlElement taskNode = new XmlDocument().CreateElement("MockTask");
     LoadedType taskClass = new LoadedType(typeof(MockTask), new AssemblyLoadInfo(typeof(MockTask).Assembly.FullName, null));
     Engine engine = new Engine(@"c:\");
     loggingHelper = new EngineLoggingServicesHelper();
     engine.LoggingServices = loggingHelper;
     Project project = new Project(engine);
     taskExecutionModule = new MockTaskExecutionModule(new EngineCallback(engine));
     // Set up some "fake data" which will be passed to the Task Execution State object
     Hashtable[] fakeArray = new Hashtable[1];
     fakeArray[0] = new Hashtable();
     projectLevelProprtiesForInference = new BuildPropertyGroup();
     projectLevelPropertiesForExecution = new BuildPropertyGroup();
     inferenceBucketItemsByName = fakeArray;
     inferenceBucketMetaData = fakeArray;
     projectLevelItemsForInference = new Hashtable();
     executionBucketItemsByName = fakeArray;
     executionBucketMetaData = fakeArray;
     projectLevelItemsForExecution = new Hashtable();
     hostObject = null;
     projectFileOfTaskNode = "In Memory";
     parentProjectFullFileName = project.FullFileName;
     nodeProxyId = engine.EngineCallback.CreateTaskContext(project, null, null, taskNode, EngineCallback.inProcNode, new BuildEventContext(BuildEventContext.InvalidNodeId, BuildEventContext.InvalidTargetId, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidTaskId));
     executionDirectory = Directory.GetCurrentDirectory();
     projectId = project.Id;
 }
Exemplo n.º 9
0
		BuildProperty [] GetProperties (BuildPropertyGroup bpg)
		{
			List<BuildProperty> list = new List<BuildProperty> ();
			foreach (BuildProperty bp in bpg)
				list.Add (bp);
			return list.ToArray ();
		}
Exemplo n.º 10
0
        /// <summary>
        /// Initialize the node with the id and the callback object
        /// </summary>
        internal Node
        (
            int nodeId, 
            LoggerDescription[] nodeLoggers, 
            IEngineCallback parentCallback,
            BuildPropertyGroup parentGlobalProperties,
            ToolsetDefinitionLocations toolsetSearchLocations,
            string parentStartupDirectory
        )
        {
            this.nodeId = nodeId;
            this.parentCallback = parentCallback;

            this.exitNodeEvent = new ManualResetEvent(false);
            this.buildRequests = new Queue<BuildRequest>();

            this.requestToLocalIdMapping = new Hashtable();
            this.lastRequestIdUsed = 0;

            this.centralizedLogging = false;
            this.nodeLoggers = nodeLoggers;

            this.localEngine = null;
            this.launchedEngineLoopThread = false;
            this.nodeShutdown = false;
            this.parentGlobalProperties = parentGlobalProperties;
            this.toolsetSearchLocations = toolsetSearchLocations;
            this.parentStartupDirectory = parentStartupDirectory;
        }
Exemplo n.º 11
0
        public void CantModifyThroughEnumerator()
        {
            BuildPropertyGroup pg = new BuildPropertyGroup();
            // Only NormalProperties are modifiable anyway
            BuildProperty p1 = new BuildProperty("name1", "value1", PropertyType.NormalProperty);
            pg.SetProperty(p1);

            BuildPropertyGroupProxy proxy = new BuildPropertyGroupProxy(pg);

            Hashtable list = new Hashtable(StringComparer.OrdinalIgnoreCase);

            // Get the one property
            foreach (DictionaryEntry prop in proxy)
            {
                list.Add(prop.Key, prop.Value);
            }

            // Change the property
            Assertion.Assert((string)list["name1"] == "value1");
            list["name1"] = "newValue";
            Assertion.Assert((string)list["name1"] == "newValue");

            // Get the property again
            list = new Hashtable(StringComparer.OrdinalIgnoreCase);
            foreach (DictionaryEntry prop in proxy)
            {
                list.Add(prop.Key, prop.Value);
            }

            // Property value hasn't changed
            Assertion.Assert((string)list["name1"] == "value1");
        }
Exemplo n.º 12
0
		public void TestAssignment ()
		{
			bpg = new BuildPropertyGroup ();
			
			Assert.AreEqual (0, bpg.Count);
			Assert.AreEqual (false, bpg.IsImported);
		}
Exemplo n.º 13
0
        public static bool Build(Project pProj, OutputWindowPane pPane, string pTarget, NameValueCollection pParams)
        {
            Microsoft.Build.BuildEngine.Engine buildEngine = new Microsoft.Build.BuildEngine.Engine();
              BuildExecutor executor = new BuildExecutor(pPane);

              RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework", false);
              if (key == null) {
            throw new Exception("Failed to determine .NET Framework install root - no .NETFramework key");
              }
              string installRoot = key.GetValue("InstallRoot") as string;
              if (installRoot == null) {
            throw new Exception("Failed to determine .NET Framework install root - no InstallRoot value");
              }
              key.Close();

              buildEngine.BinPath = Path.Combine(installRoot, string.Format("v{0}.{1}.{2}", Environment.Version.Major, Environment.Version.Minor, Environment.Version.Build));
              buildEngine.RegisterLogger(executor);

              executor.Verbosity = LoggerVerbosity.Normal;

              BuildPropertyGroup properties = new BuildPropertyGroup();
              foreach (string propKey in pParams.Keys) {
            string val = pParams[propKey];

            properties.SetProperty(propKey, val, true);
              }

              return buildEngine.BuildProjectFile(pProj.FileName, new string[]{pTarget}, properties);
        }
Exemplo n.º 14
0
        public void SimpleAddAndRetrieveProject()
        {
            // Initialize engine.
            Engine engine = new Engine(@"c:\");

            // Instantiate new project manager.
            ProjectManager projectManager = new ProjectManager();

            // Set up variables that represent the information we would be getting from 
            // the "MSBuild" task.
            string fullPath = @"c:\rajeev\temp\myapp.proj";
            BuildPropertyGroup globalProperties = new BuildPropertyGroup();
            globalProperties.SetProperty("Configuration", "Debug");

            // Create a new project that matches the information that we're pretending
            // to receive from the MSBuild task.
            Project project1 = new Project(engine);
            project1.FullFileName = fullPath;
            project1.GlobalProperties = globalProperties;

            // Add the new project to the ProjectManager.
            projectManager.AddProject(project1);

            // Try and retrieve the project from the ProjectManager based on the fullpath + globalprops,
            // and make sure we get back the same project we added.
            Assertion.AssertEquals(project1, projectManager.GetProject(fullPath, globalProperties, null));
        }
Exemplo n.º 15
0
 protected override void OnSetupDebugGroup(BuildPropertyGroup group)
 {
     group.AddNewProperty("Optimize", "false");
     group.AddNewProperty("DefineConstants", "DEBUG;TRACE");
     group.AddNewProperty("ErrorReport", "prompt");
     group.AddNewProperty("WarningLevel", "4");
 }
Exemplo n.º 16
0
 /// <summary>
 /// Special cased constructor. Where we are only going to expand properties and metadata,
 /// it's a waste of memory to use a lookup. Just use the property group.
 /// PERF: This improves the EvaluateAllItemDefinitions codepath.
 /// </summary>
 internal Expander(BuildPropertyGroup properties, string implicitMetadataItemType, Dictionary<string, string> unqualifiedItemMetadata)
 {
     this.options = ExpanderOptions.ExpandPropertiesAndMetadata;
     this.properties = properties;
     this.itemMetadata = unqualifiedItemMetadata;
     this.implicitMetadataItemType = implicitMetadataItemType;
 }
Exemplo n.º 17
0
		public BuildWhen (XmlElement whenElement, Project parentProject)
		{
			this.parentProject = parentProject;
			this.groupingCollection = new GroupingCollection (parentProject);
			if (whenElement == null)
				throw new ArgumentNullException ("whenElement");
			this.whenElement = whenElement;
			foreach (XmlElement xe in whenElement.ChildNodes) {
				switch (xe.Name) {
					case "ItemGroup":
						BuildItemGroup big = new BuildItemGroup (xe, parentProject, null, true);
						//big.BindToXml (xe);
						groupingCollection.Add (big);
						break;
					case "PropertyGroup":
						BuildPropertyGroup bpg = new BuildPropertyGroup (xe, parentProject, null, true);
						//bpg.BindToXml (xe);
						groupingCollection.Add (bpg);
						break;
					case "Choose":
						BuildChoose bc = new BuildChoose (xe, parentProject);
						groupingCollection.Add (bc);
						break;
					default:
						throw new InvalidProjectFileException ( string.Format ("Invalid element '{0}' in When.", xe.Name));
				}
			}
		}
		BuildProperty [] GetProperties (BuildPropertyGroup bpg)
		{
			BuildProperty [] arr = new BuildProperty [bpg.Count];
			int i = 0;
			foreach (BuildProperty bp in bpg)
				arr [i++] = bp;
			return arr;
		}
Exemplo n.º 19
0
        public void ConstructWithSimpleProject()
        {
            Project p = Build.UnitTests.ObjectModelHelpers.CreateInMemoryProject(basicProjectContentsWithOnePropertyGroup);
            BuildPropertyGroup group = new BuildPropertyGroup(p);

            Assertion.AssertEquals(0, group.Count);
            Assertion.AssertEquals(false, group.IsImported);
        }
Exemplo n.º 20
0
		static string GetPropValue (BuildPropertyGroup bpg, string name)
		{
			foreach (BuildProperty bp in bpg) {
				if (bp.Name == name) {
					return bp.FinalValue;
				}
			}
			return String.Empty;
		}
Exemplo n.º 21
0
        public void ExpandAllIntoTaskItems1()
        {
            BuildPropertyGroup pg = new BuildPropertyGroup();
            Expander expander = new Expander(pg);

            List<TaskItem> itemsOut = expander.ExpandAllIntoTaskItems("foo", null);

            ObjectModelHelpers.AssertItemsMatch(@"foo", itemsOut.ToArray());
        }
Exemplo n.º 22
0
 public MockEngine(bool logToConsole)
 {
     mockLogger = new MockLogger();
     this.logToConsole = logToConsole;
     this.engine = new Engine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath));
     this.engine.RegisterLogger(new ConsoleLogger());
     this.engine.RegisterLogger(mockLogger);
     engineGlobalProperties = new BuildPropertyGroup();
 }
Exemplo n.º 23
0
		public void TestAddNewProperty1 ()
		{
			string name = "name";
			string value = "value";

			bpg = new BuildPropertyGroup ();

			bpg.AddNewProperty (name, value);
		}
Exemplo n.º 24
0
        /// <summary>
        /// Overloaded constructor.
        /// </summary>
        /// <param name="project">An instance of a build project</param>
        /// <exception cref="ArgumentNullException">Is thrown if the passed Project is null.</exception>
        internal GlobalPropertyHandler(MSBuild.Project project)
        {
            Debug.Assert(project != null, "The project parameter passed cannot be null");

            this.globalProjectProperties = project.GlobalProperties;

            Debug.Assert(project.ParentEngine != null, "The parent engine has not been initialized");

            this.globalEngineProperties = project.ParentEngine.GlobalProperties;
        }
Exemplo n.º 25
0
        public void TestConstructor()
        {
            BuildPropertyGroup default_scope = new BuildPropertyGroup(new Project());
            Assertion.AssertNotNull(default_scope);

            CacheScope testScope = new CacheScope("Test.proj", default_scope, "2.0");
            Assert.AreEqual(testScope.ScopeProperties, default_scope, "Expected ScopeProperties to be set");

            // We should have detached the parent project from the property group, to avoid holding on to it in the cache
            Assertion.AssertEquals(null, testScope.ScopeProperties.ParentProject);
        }
Exemplo n.º 26
0
 /// <summary>
 /// This constructor creates a scope for a particular name and set of properties
 /// </summary>
 internal CacheScope(string scopeName, BuildPropertyGroup scopeProperties, string scopeToolsVersion)
 {
     // Make certain we don't cache a reference to a Project object, which would defeat 
     // the purpose of this cache
     scopeProperties.ClearParentProject(); 
     
     this.scopeName = scopeName;
     this.scopeToolsVersion = scopeToolsVersion;
     this.scopeProperties = scopeProperties;
     this.cacheContents = new Hashtable(StringComparer.OrdinalIgnoreCase);
 }
Exemplo n.º 27
0
        /// <summary>
        /// Go through each &lt;BuildItemDefinition&gt; element in order, evaluating it using the
        /// supplied properties and any previously evaluated definitions, to build up a complete
        /// library of item types and their default metadata values.
        /// </summary>
        internal void Evaluate(BuildPropertyGroup evaluatedProperties)
        {
            // Clear out previous data first
            itemDefinitionsDictionary.Clear();

            foreach (BuildItemDefinitionGroupXml itemDefinitionGroupXml in itemDefinitions)
            {
                itemDefinitionGroupXml.Evaluate(evaluatedProperties, itemDefinitionsDictionary);
            }

            evaluated = true;
        }
Exemplo n.º 28
0
        public void PropertyGroupEmpty()
        {
            string content = @"
            <Target Name='t' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
                <PropertyGroup/>
            </Target>";
            IntrinsicTask task = CreateIntrinsicTask(content);
            BuildPropertyGroup properties = new BuildPropertyGroup();
            ExecuteTask(task, LookupHelpers.CreateLookup(properties));

            Assertion.AssertEquals(0, properties.Count);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Called on the main node only.
        /// </summary>
        public Exception PostCacheEntriesToHost(int nodeId, CacheEntry[] entries, string scopeName, BuildPropertyGroup scopeProperties, string scopeToolsVersion, CacheContentType cacheContentType)
        {
            try
            {
                parentEngine.CacheManager.SetCacheEntries(entries, scopeName, scopeProperties, scopeToolsVersion, cacheContentType);
            }
            catch (InvalidOperationException e)
            {
                return e;
            }

            return null;
        }
Exemplo n.º 30
0
        /// <summary>
        /// Constructor that also associates a set of properties with the tools version
        /// </summary>
        /// <param name="toolsVersion">Name of the toolset</param>
        /// <param name="toolsPath">Path to this toolset's tasks and targets</param>
        /// <param name="buildProperties">Properties that should be associated with the Toolset.
        /// May be null, in which case an empty property group will be used.</param>
        public Toolset(string toolsVersion, string toolsPath, BuildPropertyGroup buildProperties)
        {
            ErrorUtilities.VerifyThrowArgumentLength(toolsVersion, "toolsVersion");
            ErrorUtilities.VerifyThrowArgumentLength(toolsPath, "toolsPath");

            this.toolsVersion = toolsVersion;
            this.ToolsPath = toolsPath;

            this.properties = new BuildPropertyGroup();
            if (buildProperties != null)
            {
                this.properties.ImportProperties(buildProperties);
            }
        }