public override bool Execute()
        {
            bool result = true;

            string file = Path.Combine(m_stubsPath, m_name + ".featureproj");

            try
            {
                Project proj = new Project();
                proj.DefaultToolsVersion = "3.5";
                proj.DefaultTargets      = "Build";

                BuildPropertyGroup bpg = proj.AddNewPropertyGroup(true);
                bpg.AddNewProperty("FeatureName", m_name);
                bpg.AddNewProperty("Guid", System.Guid.NewGuid().ToString("B"));
                bpg.AddNewProperty("Description", "");
                bpg.AddNewProperty("Groups", "");

                BuildItemGroup big = proj.AddNewItemGroup();
                big.AddNewItem("InteropFeature", Path.GetFileNameWithoutExtension(m_assemblyName).Replace('.', '_'));
                big.AddNewItem("DriverLibs", Path.GetFileNameWithoutExtension(m_assemblyName).Replace('.', '_') + ".$(LIB_EXT)");
                big.AddNewItem("MMP_DAT_CreateDatabase", "$(BUILD_TREE_CLIENT)\\pe\\" + m_assemblyName);
                big.AddNewItem("RequiredProjects", Path.Combine(m_stubsPath, m_nativeProjectFile));

                proj.Save(file);
            }
            catch (Exception e)
            {
                Log.LogError("Error trying to create feature project file \"" + file + "\": " + e.Message);
                result = false;
            }

            return(result);
        }
示例#2
0
        public void ValidUnqualifiedMetadataReference()
        {
            List <string> parameters = new List <string>();

            parameters.Add("@(File)");
            parameters.Add("%(Culture)");

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);

            BuildItemGroup items = new BuildItemGroup();

            itemsByType["FILE"] = items;

            BuildItem a = items.AddNewItem("File", "a.foo");
            BuildItem b = items.AddNewItem("File", "b.foo");

            a.SetMetadata("Culture", "fr-fr");
            b.SetMetadata("Culture", "en-en");

            BuildPropertyGroup properties = new BuildPropertyGroup();

            ArrayList buckets = BatchingEngine.PrepareBatchingBuckets(new XmlDocument().CreateElement("Foo"), parameters, CreateLookup(itemsByType, properties));

            Assertion.AssertEquals(2, buckets.Count);
        }
示例#3
0
        public void InputItemThatCorrelatesWithMultipleTransformOutputItems()
        {
            string inputs  = "@(Items)";
            string outputs = "@(Items->'%(Filename).dll');@(Items->'%(Filename).xml')";

            FileWriteInfo[] filesToAnalyze = new FileWriteInfo[]
            {
                new FileWriteInfo("a.cs", yesterday),
                new FileWriteInfo("a.dll", today),
                new FileWriteInfo("a.xml", today),
                new FileWriteInfo("b.cs", yesterday),
                new FileWriteInfo("b.dll", twoDaysAgo),
                new FileWriteInfo("b.xml", today),
                new FileWriteInfo("c.cs", yesterday),
                new FileWriteInfo("c.dll", today),
                new FileWriteInfo("c.xml", today)
            };

            BuildItemGroup items = new BuildItemGroup();

            items.AddNewItem("Items", "a.cs");
            items.AddNewItem("Items", "b.cs");
            items.AddNewItem("Items", "c.cs");

            Hashtable itemsByName = new Hashtable(StringComparer.OrdinalIgnoreCase);

            itemsByName.Add("Items", items);

            DependencyAnalysisResult result = PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs);

            Assertion.AssertEquals("Should only build partially.", DependencyAnalysisResult.IncrementalBuild, result);
        }
示例#4
0
        public static void Save(object obj, Stream stream)
        {
            string path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(path);

            try
            {
                string xamlFile = Path.Combine(path, "input.xaml");
                string projFile = Path.Combine(path, "project.proj");

                using (FileStream fs = File.Create(xamlFile))
                {
                    XamlWriter.Save(obj, fs);
                }

                Engine engine = new Engine();
#pragma warning disable CS0618 // Type or member is obsolete
                engine.BinPath = RuntimeEnvironment.GetRuntimeDirectory();
#pragma warning restore CS0618 // Type or member is obsolete
                Project            project = engine.CreateNewProject();
                BuildPropertyGroup pgroup  = project.AddNewPropertyGroup(false);
                pgroup.AddNewProperty("AssemblyName", "temp");
                pgroup.AddNewProperty("OutputType", "Library");
                pgroup.AddNewProperty("IntermediateOutputPath", ".");
                pgroup.AddNewProperty("MarkupCompilePass1DependsOn", "ResolveReferences");

                BuildItemGroup igroup = project.AddNewItemGroup();
                igroup.AddNewItem("Page", "input.xaml");
                igroup.AddNewItem("Reference", "WindowsBase");
                igroup.AddNewItem("Reference", "PresentationCore");
                igroup.AddNewItem("Reference", "PresentationFramework");

                project.AddNewImport(@"$(MSBuildBinPath)\Microsoft.CSharp.targets", null);
                project.AddNewImport(@"$(MSBuildBinPath)\Microsoft.WinFX.targets", null);
                project.FullFileName = projFile;

                if (engine.BuildProject(project, "MarkupCompilePass1"))
                {
                    byte[] buffer = new byte[1024];
                    using (FileStream fs = File.OpenRead(Path.Combine(path, "input.baml")))
                    {
                        int read = 0;
                        while (0 < (read = fs.Read(buffer, 0, buffer.Length)))
                        {
                            stream.Write(buffer, 0, read);
                        }
                    }
                }
                else
                {
                    // attach a logger to the Engine if you need better errors
                    throw new System.Exception("Baml compilation failed.");
                }
            }
            finally
            {
                Directory.Delete(path, true);
            }
        }
示例#5
0
        public void TestClone2()
        {
            BuildItemGroup big = new BuildItemGroup();

            big.AddNewItem("a", "a");
            big.AddNewItem("b", "a");

            BuildItemGroup big2 = big.Clone(true);

            BuildItem[] items = big2.ToArray();

            Assert.AreEqual(2, big2.Count, "A1");

            Assert.AreEqual(String.Empty, items [0].Condition, "A2");
            Assert.AreEqual(String.Empty, items [0].Exclude, "A3");
            Assert.AreEqual("a", items [0].FinalItemSpec, "A4");
            Assert.AreEqual("a", items [0].Include, "A5");
            Assert.IsFalse(items [0].IsImported, "A6");
            Assert.AreEqual("a", items [0].Name, "A7");

            Assert.AreEqual(String.Empty, items [1].Condition, "A8");
            Assert.AreEqual(String.Empty, items [1].Exclude, "A9");
            Assert.AreEqual("a", items [1].FinalItemSpec, "A10");
            Assert.AreEqual("a", items [1].Include, "A11");
            Assert.IsFalse(items [1].IsImported, "A12");
            Assert.AreEqual("b", items [1].Name, "A13");
        }
示例#6
0
        internal static Expander GetExpander()
        {
            BuildPropertyGroup propertyGroup = new BuildPropertyGroup();

            propertyGroup.SetProperty("Property1", "Value1");
            propertyGroup.SetProperty("Property2", "Value2");
            propertyGroup.SetProperty("Property3", "Value3");
            propertyGroup.SetProperty("Property4", "Value4");
            propertyGroup.SetProperty("Property5", "Value5");

            BuildItemGroup itemGroup1 = new BuildItemGroup();

            itemGroup1.AddNewItem("FirstItem", "FirstValue1");
            itemGroup1.AddNewItem("FirstItem", "FirstValue2");
            itemGroup1.AddNewItem("FirstItem", "FirstValue3");

            BuildItemGroup itemGroup2 = new BuildItemGroup();

            itemGroup2.AddNewItem("SecondItem", "SecondValue1");
            itemGroup2.AddNewItem("SecondItem", "SecondValue2");
            itemGroup2.AddNewItem("SecondItem", "SecondValue3");

            BuildItemGroup itemGroup3 = new BuildItemGroup();

            itemGroup3.AddNewItem("ThirdItem", "ThirdValue1");

            Hashtable itemsByName = new Hashtable(StringComparer.OrdinalIgnoreCase);

            itemsByName["FirstItem"]  = itemGroup1;
            itemsByName["SecondItem"] = itemGroup2;
            itemsByName["ThirdItem"]  = itemGroup3;

            return(new Expander(new ReadOnlyLookup(itemsByName, propertyGroup)));
        }
示例#7
0
        public void TestIndexer1()
        {
            BuildItemGroup big = new BuildItemGroup();

            big.AddNewItem("a", "b");
            big.AddNewItem("c", "d");

            Assert.AreEqual("a", big [0].Name, "A1");
            Assert.AreEqual("c", big [1].Name, "A2");
        }
示例#8
0
        public void TestRemoveItemAt3()
        {
            BuildItemGroup big = new BuildItemGroup();

            big.AddNewItem("a", "b");
            big.AddNewItem("b", "c");
            big.AddNewItem("c", "d");

            big.RemoveItemAt(3);
        }
示例#9
0
        public void AddNewItem1()
        {
            XmlElement     ig    = CreatePersistedItemGroupElement();
            BuildItemGroup group = new BuildItemGroup(ig, false, new Project());

            group.AddNewItem("j", "j1");
            group.AddNewItem("j", "j2;", true /*literal*/);

            Assertion.AssertEquals(4, group.Count);
            Assertion.AssertEquals("j1", group[2].Include);
            Assertion.AssertEquals("j2%3b", group[3].Include);
        }
示例#10
0
        public void TestAddNewItem5()
        {
            BuildItemGroup big = new BuildItemGroup();

            big.AddNewItem("I1", "Value");

            BuildItem bi = big.AddNewItem("I2", "@(I1)");

            Assert.AreEqual("@(I1)", bi.FinalItemSpec, "A1");
            Assert.AreEqual("@(I1)", bi.Include, "A2");
            Assert.AreEqual(2, big.Count, "A3");
        }
示例#11
0
        public void TestClear1()
        {
            BuildItemGroup big = new BuildItemGroup();

            big.AddNewItem("a", "a");
            big.AddNewItem("b", "a");

            Assert.AreEqual(2, big.Count, "A1");

            big.Clear();

            Assert.AreEqual(0, big.Count, "A2");
        }
        public void RemoveItemAllOfSeveral()
        {
            BuildItemGroup group = new BuildItemGroup();

            BuildItem[] item = new BuildItem[3];
            item[0] = group.AddNewItem("n1", "i1");
            item[1] = group.AddNewItem("n2", "i2");
            item[2] = group.AddNewItem("n3", "i3");

            group.RemoveItem(item[0]);
            group.RemoveItem(item[1]);
            group.RemoveItem(item[2]);

            Assertion.AssertEquals(0, group.Count);
        }
示例#13
0
        public void TestRemoveItemAt1()
        {
            BuildItemGroup big = new BuildItemGroup();

            big.AddNewItem("a", "b");
            big.AddNewItem("b", "c");
            big.AddNewItem("c", "d");

            big.RemoveItemAt(1);

            BuildItem[] items = big.ToArray();
            Assert.AreEqual(2, big.Count, "A1");
            Assert.AreEqual("a", items [0].Name, "A2");
            Assert.AreEqual("c", items [1].Name, "A3");
        }
 public void RemoveEvaluatedItemSuccess()
 {
     try
     {
         string         includePath = Path.Combine(ObjectModelHelpers.TempProjectDir, "*.foo");
         List <string>  files       = CompatibilityTestHelpers.CreateFiles(4, "foo", "foo", ObjectModelHelpers.TempProjectDir);
         Project        p           = new Project(new Engine());
         BuildItemGroup group       = p.AddNewItemGroup();
         group.AddNewItem("foos", includePath);
         object o = p.EvaluatedItems;
         files.RemoveAt(files.IndexOf(p.EvaluatedItems[0].FinalItemSpec));
         p.RemoveItem(p.EvaluatedItems[0]);
         int i = 0;
         foreach (string fileName in files)
         {
             Assertion.AssertEquals(includePath, group[0].FinalItemSpec);
             Assertion.AssertEquals(includePath, group[0].Include);
             Assertion.AssertEquals(fileName, p.EvaluatedItems[i].Include);
             Assertion.AssertEquals(fileName, p.EvaluatedItems[i].FinalItemSpec);
             i++;
         }
     }
     finally
     {
         CompatibilityTestHelpers.CleanupDirectory(ObjectModelHelpers.TempProjectDir);
     }
 }
示例#15
0
        private void OnCleanUp()
        {
            String sourceRoot = ConfigurationManager.AppSettings["source_root"];
            String csprojName = ConfigurationManager.AppSettings["csproj_name"];

            String csprojFile = sourceRoot + csprojName;

            Project project = new Project();

            project.Load(csprojFile);

            project.RemoveItemsByName("Content");

            // 补上img文件夹
            BuildItemGroup itemGroup = project.AddNewItemGroup();

            String[] bookFiles = Directory.GetFileSystemEntries(sourceRoot + "_static\\img\\");

            foreach (var file in bookFiles)
            {
                itemGroup.AddNewItem("Content", "_static\\img\\" + Path.GetFileName(file));
            }

            project.Save(csprojFile);
        }
示例#16
0
        public void TestToArray1()
        {
            BuildItemGroup big = new BuildItemGroup();

            BuildItem[] items = big.ToArray();

            Assert.AreEqual(0, items.Length, "A1");

            big.AddNewItem("a", "b");
            big.AddNewItem("c", "d");

            items = big.ToArray();

            Assert.AreEqual("a", items [0].Name, "A2");
            Assert.AreEqual("c", items [1].Name, "A3");
        }
        public void AddNewItemNameToNull()
        {
            project.LoadXml(ProjectContentWithOneBuildItemGroupThreeBuildItems);
            BuildItemGroup group = GetBuildItemGroupFromProject(project, false);

            group.AddNewItem(null, "i");
        }
        public void AddNewItemNameToEmptyString()
        {
            project.LoadXml(ProjectContentWithOneBuildItemGroupThreeBuildItems);
            BuildItemGroup group = GetBuildItemGroupFromProject(project, false);

            group.AddNewItem(String.Empty, "i");
        }
        public bool AddReference(string grpCondition, AssemblyName assembly, string condition, string hintPath, bool copyLocal, bool specificVersion)
        {
            BuildItemGroup grpAdding = FristReferenceGroup(grpCondition);

            if (!File.Exists(hintPath))
            {
                throw new ApplicationException("Unable to locate path for: " + assembly.ToString());
            }
            if (specificVersion || assembly.Version != null)
            {
                if (File.Exists(hintPath))
                {
                    specificVersion = true;
                    assembly        = System.Reflection.AssemblyName.GetAssemblyName(hintPath);
                }
            }
            BuildItem addedItem = grpAdding.AddNewItem("Reference", !specificVersion ? assembly.Name : assembly.FullName);

            addedItem.Condition = condition;
            addedItem.SetMetadata("SpecificVersion", specificVersion.ToString());
            addedItem.SetMetadata("Private", copyLocal.ToString());
            if (!String.IsNullOrEmpty(hintPath))
            {
                addedItem.SetMetadata("HintPath", MakeProjectRelativePath(hintPath));
            }

            _refCache.Add(new ProjectRef(addedItem, GetProjectPath));
            return(true);
        }
        public void AddNewItemWithSpecialCharactersInName()
        {
            project.LoadXml(ProjectContentWithOneBuildItemGroupThreeBuildItems);
            BuildItemGroup group = GetBuildItemGroupFromProject(project, false);

            group.AddNewItem(SpecialCharacters, "i");
        }
 public void RemoveEvaluatedItem1()
 {
     try
     {
         List <string>  files = CompatibilityTestHelpers.CreateFiles(4, "foo", "foo", ObjectModelHelpers.TempProjectDir);
         Project        p     = new Project(new Engine());
         BuildItemGroup group = p.AddNewItemGroup();
         group.AddNewItem("foos", Path.Combine(ObjectModelHelpers.TempProjectDir, "*.foo"));
         object o = p.EvaluatedItems;           // this causes the failure
         group.RemoveItem(p.EvaluatedItems[0]); // Exception thrown here
         Assertion.Fail("success as failure");  // should not get here due to exception above
     }
     catch (Exception e)
     {
         if (!(e.GetType().ToString().Contains("InternalErrorException")))
         {
             Assertion.Fail(e.Message + " was thrown");
         }
         else
         {
             Assertion.Assert("InternalErrorException was thrown", true);
         }
     }
     finally
     {
         CompatibilityTestHelpers.CleanupDirectory(ObjectModelHelpers.TempProjectDir);
     }
 }
示例#22
0
        // returns number of levels
        int AddBuildLevels(Project p, List <TargetInfo> solutionTargets, Dictionary <Guid, ProjectInfo> projectInfos,
                           ref List <ProjectInfo>[] infosByLevel)
        {
            infosByLevel = TopologicalSort <ProjectInfo> (projectInfos.Values);

            foreach (TargetInfo targetInfo in solutionTargets)
            {
                BuildItemGroup big = p.AddNewItemGroup();
                big.Condition = String.Format(" ('$(Configuration)' == '{0}') and ('$(Platform)' == '{1}') ",
                                              targetInfo.Configuration, targetInfo.Platform);

                //FIXME: every level has projects that can be built in parallel.
                //	 levels are ordered on the basis of the dependency graph

                for (int i = 0; i < infosByLevel.Length; i++)
                {
                    string build_level   = String.Format("BuildLevel{0}", i);
                    string skip_level    = String.Format("SkipLevel{0}", i);
                    string missing_level = String.Format("MissingConfigLevel{0}", i);

                    foreach (ProjectInfo projectInfo in infosByLevel[i])
                    {
                        TargetInfo projectTargetInfo;
                        if (!projectInfo.TargetMap.TryGetValue(targetInfo, out projectTargetInfo))
                        {
                            // missing project config
                            big.AddNewItem(missing_level, projectInfo.Name);
                            continue;
                        }

                        if (projectTargetInfo.Build)
                        {
                            BuildItem item = big.AddNewItem(build_level, projectInfo.FileName);
                            item.SetMetadata("Configuration", projectTargetInfo.Configuration);
                            item.SetMetadata("Platform", projectTargetInfo.Platform);
                        }
                        else
                        {
                            // build disabled
                            big.AddNewItem(skip_level, projectInfo.Name);
                        }
                    }
                }
            }

            return(infosByLevel.Length);
        }
        public void IsImportedInMemoryBuildItemGroup()
        {
            BuildItemGroup group = new BuildItemGroup();

            group.AddNewItem("n", "i");

            Assertion.AssertEquals(false, group.IsImported);
        }
        public void AddNewItemNameToNullMemoryGroup()
        {
            BuildItemGroup group = new BuildItemGroup();

            group.AddNewItem(null, "i");

            Assertion.AssertEquals(1, group.Count);
        }
        public void RemoveItemAtFirstItem()
        {
            BuildItemGroup group = new BuildItemGroup();

            group.AddNewItem("n1", "i1");
            group.AddNewItem("n2", "i2");
            group.AddNewItem("n3", "i3");

            group.RemoveItemAt(0);

            Assertion.AssertEquals(2, group.Count);

            Dictionary <string, string> items = GetDictionaryOfBuildItemsInBuildItemsGroup(group);

            Assertion.AssertEquals("i2", items["n2"]);
            Assertion.AssertEquals("i3", items["n3"]);
        }
示例#26
0
        public void AddContent(string filename, string importer, string processor)
        {
            BuildItem content = m_contentGroup.AddNewItem("Content", filename);

            content.SetMetadata("Importer", importer);
            content.SetMetadata("Processor", processor);
            content.SetMetadata("Name", Path.GetFileNameWithoutExtension(filename));
        }
示例#27
0
        public void TestGetEnumerator()
        {
            BuildItemGroup big = new BuildItemGroup();

            big.AddNewItem("a", "c");
            big.AddNewItem("b", "d");

            IEnumerator e = big.GetEnumerator();

            e.MoveNext();
            Assert.AreEqual("a", ((BuildItem)e.Current).Name, "A1");
            Assert.AreEqual("c", ((BuildItem)e.Current).FinalItemSpec, "A2");
            e.MoveNext();
            Assert.AreEqual("b", ((BuildItem)e.Current).Name, "A3");
            Assert.AreEqual("d", ((BuildItem)e.Current).FinalItemSpec, "A4");

            Assert.IsFalse(e.MoveNext());
        }
        public void AddNewItemWithSpecialCharactersInValue()
        {
            project.LoadXml(ProjectContentWithOneBuildItemGroupThreeBuildItems);
            BuildItemGroup group = GetBuildItemGroupFromProject(project, false);

            group.AddNewItem("n4", SpecialCharacters);

            Dictionary <string, string> items = GetDictionaryOfBuildItemsInProject(project, false);

            Assertion.AssertEquals(SpecialCharacters, items["n4"]);
        }
        public void AddNewItemSimpleNameItemIncludeWithTreatPropertyValueAsLiteralFalse()
        {
            project.LoadXml(ProjectContentWithOneBuildItemGroupThreeBuildItems);
            BuildItemGroup group = GetBuildItemGroupFromProject(project, false);

            group.AddNewItem("n4", EscapableCharacters, false);

            Dictionary <string, string> items = GetDictionaryOfBuildItemsInProject(project, false);

            Console.WriteLine("'{0}'", items["n4"].ToString());
            Assertion.AssertEquals(EscapableCharacters, items["n4"]);
        }
        public bool AddReference(string grpCondition, ProjectInfo project)
        {
            BuildItemGroup grpAdding = FristReferenceGroup(grpCondition);
            string         file      = this.MakeProjectRelativePath(project.FullName);

            BuildItem addedItem = grpAdding.AddNewItem("ProjectReference", file);

            addedItem.SetMetadata("Project", project.ProjectGuid.ToString().ToUpper());
            addedItem.SetMetadata("Name", project.AssemblyName);

            _refCache.Add(new ProjectRef(addedItem, GetProjectPath));
            return(true);
        }
示例#31
0
	public BuildItem AddGeneratedFileBuildItem(BuildItemGroup buildItemGroup, string sourceFileName, string outputFileName)
	{
		if (outputFileName == null || outputFileName.Length == 0)
		{
			outputFileName = GetOutputFileDefaultName(sourceFileName);
		}
		BuildItem buildItem = buildItemGroup.AddNewItem("None", outputFileName);
		buildItem.SetMetadata(ITEMMETADATA_AUTOGEN, "True");
		buildItem.SetMetadata(ITEMMETADATA_DEPENDENTUPON, sourceFileName);
		buildItem.SetMetadata(ITEMMETADATA_ORMGENERATOR, this.OfficialName);
		return buildItem;
	}