Esempio n. 1
0
        public void SetDependsOnTargets()
        {
            ProjectRootElement   project = ProjectRootElement.Create();
            ProjectTargetElement target  = project.AddTarget("t");

            Helpers.ClearDirtyFlag(project);

            target.DependsOnTargets = "dot";

            Assert.Equal("dot", target.DependsOnTargets);
            Assert.True(project.HasUnsavedChanges);
        }
Esempio n. 2
0
        public void SetInputs()
        {
            ProjectRootElement   project = ProjectRootElement.Create();
            ProjectTargetElement target  = project.AddTarget("t");

            Helpers.ClearDirtyFlag(project);

            target.Inputs = "in";

            Assert.Equal("in", target.Inputs);
            Assert.Equal(true, project.HasUnsavedChanges);
        }
Esempio n. 3
0
        public void SetKeepDuplicateOutputs()
        {
            ProjectRootElement   project = ProjectRootElement.Create();
            ProjectTargetElement target  = project.AddTarget("t");

            Helpers.ClearDirtyFlag(project);

            target.KeepDuplicateOutputs = "true";

            Assert.Equal("true", target.KeepDuplicateOutputs);
            Assert.True(project.HasUnsavedChanges);
        }
Esempio n. 4
0
        public void SetCondition()
        {
            ProjectRootElement   project = ProjectRootElement.Create();
            ProjectTargetElement target  = project.AddTarget("t");

            Helpers.ClearDirtyFlag(project);

            target.Condition = "c";

            Assert.Equal("c", target.Condition);
            Assert.True(project.HasUnsavedChanges);
        }
Esempio n. 5
0
        public void SetName()
        {
            ProjectRootElement   project = ProjectRootElement.Create();
            ProjectTargetElement target  = project.AddTarget("t");

            Helpers.ClearDirtyFlag(project);

            target.Name = "t2";

            Assert.Equal("t2", target.Name);
            Assert.True(project.HasUnsavedChanges);
        }
Esempio n. 6
0
            private (bool success, ProjectTargetElement target) FindTargetToRemove(ProjectRootElement projectXml)
            {
                ProjectTargetElement foundTarget = projectXml.Targets
                                                   .Where(target =>
                                                          StringComparer.OrdinalIgnoreCase.Compare(GetTarget(target), BuildEvent) == 0 &&
                                                          StringComparer.OrdinalIgnoreCase.Compare(target.Name, TargetName) == 0 &&
                                                          target.Children.Count == 1 &&
                                                          target.Tasks.Count == 1 &&
                                                          StringComparer.OrdinalIgnoreCase.Compare(target.Tasks.First().Name, ExecTask) == 0)
                                                   .FirstOrDefault();

                return(success : foundTarget != null, target : foundTarget);
            }
        public void ShouldHaveFilePathLocationEvenIfNotLoadedNorSavedYet()
        {
            ProjectRootElement project = ProjectRootElement.Create();

            project.FullPath = "c:\\x";
            ProjectTargetElement target = project.CreateTargetElement("t");

            target.Outputs = "o";
            project.AppendChild(target);

            Assert.Equal(project.FullPath, target.Location.File);
            Assert.Equal(project.FullPath, target.OutputsLocation.File);
        }
Esempio n. 8
0
        private void CfgDepPostProc(ProjectTargetElement dep, CmdType type)
        {
            if ((type & CmdType.DependentX86X64) == CmdType.DependentX86X64)
            {
                AddTaskForX86X64(dep, type, 86);
                AddTaskForX86X64(dep, type, 64);
            }

            if ((type & CmdType.DependentIntermediateFiles) == CmdType.DependentIntermediateFiles)
            {
                AddTasksIntermediateFiles(dep, type, "Before");
                AddTasksIntermediateFiles(dep, type, "After");
            }
        }
Esempio n. 9
0
        public void ReadEmptyTarget()
        {
            string content = @"
                    <Project>
                        <Target Name='t'/>
                    </Project>
                ";

            ProjectRootElement   project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);

            Assert.Equal(0, Helpers.Count(target.Children));
            Assert.True(project.HasUnsavedChanges);
        }
Esempio n. 10
0
        public void SetCondition()
        {
            ProjectRootElement    project = ProjectRootElement.Create();
            ProjectTargetElement  target  = project.AddTarget("t");
            ProjectOnErrorElement onError = project.CreateOnErrorElement("et");

            target.AppendChild(onError);
            Helpers.ClearDirtyFlag(project);

            onError.Condition = "c";

            Assert.AreEqual("c", onError.Condition);
            Assert.AreEqual(true, project.HasUnsavedChanges);
        }
Esempio n. 11
0
        public void SetExecuteTargets()
        {
            ProjectRootElement    project = ProjectRootElement.Create();
            ProjectTargetElement  target  = project.AddTarget("t");
            ProjectOnErrorElement onError = project.CreateOnErrorElement("et");

            target.AppendChild(onError);
            Helpers.ClearDirtyFlag(project);

            onError.ExecuteTargetsAttribute = "et2";

            Assert.AreEqual("et2", onError.ExecuteTargetsAttribute);
            Assert.AreEqual(true, project.HasUnsavedChanges);
        }
        public void ReadEmptyTarget()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t'/>
                    </Project>
                ";

            ProjectRootElement   project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);

            Assert.AreEqual(0, Helpers.Count(target.Children));
            Assert.AreEqual(true, project.HasUnsavedChanges);
        }
        public void SetParameters()
        {
            ProjectTargetElement target = GetTargetXml();

            target.Inputs           = "ib";
            target.Outputs          = "ob";
            target.DependsOnTargets = "db";
            target.Condition        = "cb";

            Assert.AreEqual("ib", target.Inputs);
            Assert.AreEqual("ob", target.Outputs);
            Assert.AreEqual("db", target.DependsOnTargets);
            Assert.AreEqual("cb", target.Condition);
        }
        public void ReadTargetTwoTasks()
        {
            ProjectTargetElement target = GetTargetXml();

            var tasks = Helpers.MakeList(target.Children);

            Assert.AreEqual(2, tasks.Count);

            ProjectTaskElement task1 = (ProjectTaskElement)tasks[0];
            ProjectTaskElement task2 = (ProjectTaskElement)tasks[1];

            Assert.AreEqual("t1", task1.Name);
            Assert.AreEqual("t2", task2.Name);
        }
        static void ResolveAssemblies(ProjectTargetElement target, List<IKVM.Reflection.Assembly> assemblies)
        {
            var resolveAssemblies = target.AddTask("ResolveAssemblies");
            var assemblyPaths = assemblies.Select(a => a.Location).ToList();
            //NOTE: [Export] requires Mono.Android.Export.dll
            assemblyPaths.Add(XamarinAndroid.FindAssembly("Mono.Android.Export.dll"));

            resolveAssemblies.SetParameter("Assemblies", string.Join(";", assemblyPaths));
            resolveAssemblies.SetParameter("LinkMode", LinkMode);
            resolveAssemblies.SetParameter("ReferenceAssembliesDirectory", "$(TargetFrameworkDirectory)");
            resolveAssemblies.AddOutputItem("ResolvedAssemblies", "ResolvedAssemblies");
            resolveAssemblies.AddOutputItem("ResolvedUserAssemblies", "ResolvedUserAssemblies");
            resolveAssemblies.AddOutputItem("ResolvedFrameworkAssemblies", "ResolvedFrameworkAssemblies");
        }
        private static ProjectTaskElement GetNamedTask(ProjectTargetElement target, string taskName)
        {
            if (target != null)
            {
                foreach (ProjectTaskElement task in target.Tasks)
                {
                    if (task.Name == taskName)
                    {
                        return(task);
                    }
                }
            }

            return(null);
        }
            private void SetParameter(ProjectRootElement projectXml, string unevaluatedPropertyValue)
            {
                ProjectTaskElement?execTask = FindExecTaskInTargets(projectXml);

                if (execTask != null)
                {
                    SetExecParameter(execTask, unevaluatedPropertyValue);
                }
                else
                {
                    ProjectTargetElement target = projectXml.AddTarget(TargetName);
                    SetTargetDependencies(target);
                    execTask = target.AddTask(ExecTask);
                    SetExecParameter(execTask, unevaluatedPropertyValue);
                }
            }
Esempio n. 18
0
        private static ProjectTargetElement GetTargetXml()
        {
            string content = @"
                    <Project>
                        <Target Name='t' Inputs='i' Outputs='o' DependsOnTargets='d' Condition='c'>
                            <t1/>
                            <t2/>
                        </Target>
                    </Project>
                ";

            ProjectRootElement   project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);

            return(target);
        }
        private static ProjectOnErrorElement GetOnError()
        {
            string content = @"
                    <Project>
                        <Target Name='t'>
                            <OnError ExecuteTargets='t' Condition='c'/>
                        </Target>
                    </Project>
                ";

            ProjectRootElement    project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement  target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);
            ProjectOnErrorElement onError = (ProjectOnErrorElement)Helpers.GetFirst(target.Children);

            return(onError);
        }
        public void XmlLocationsAreCached()
        {
            ProjectRootElement project = ProjectRootElement.Create();

            project.FullPath = "c:\\x";
            ProjectTargetElement target = project.CreateTargetElement("t");

            target.Outputs = "o";
            project.AppendChild(target);

            ElementLocation e1 = target.Location;
            ElementLocation e2 = target.OutputsLocation;

            Assert.Equal(true, Object.ReferenceEquals(e1, target.Location));
            Assert.Equal(true, Object.ReferenceEquals(e2, target.OutputsLocation));
        }
        /// <summary>
        /// Helper to get an empty ProjectTargetElement with various attributes and two tasks
        /// </summary>
        private static ProjectTargetElement GetTargetXml()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t' Inputs='i' Outputs='o' DependsOnTargets='d' Condition='c'>
                            <t1/>
                            <t2/>
                        </Target>
                    </Project>
                ";

            ProjectRootElement   project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);

            return(target);
        }
Esempio n. 22
0
        /// <summary>
        /// Get a basic ProjectOnErrorElement
        /// </summary>
        private static ProjectOnErrorElement GetOnError()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t'>
                            <OnError ExecuteTargets='t' Condition='c'/>
                        </Target>
                    </Project>
                ";

            ProjectRootElement    project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement  target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);
            ProjectOnErrorElement onError = (ProjectOnErrorElement)Helpers.GetFirst(target.Children);

            return(onError);
        }
Esempio n. 23
0
        public void ReadMissingExecuteTargets()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t'>
                            <OnError/>
                        </Target>
                    </Project>
                ";

            ProjectRootElement    project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement  target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);
            ProjectOnErrorElement onError = (ProjectOnErrorElement)Helpers.GetFirst(target.Children);

            Assert.AreEqual(String.Empty, onError.ExecuteTargetsAttribute);
        }
Esempio n. 24
0
            private void SetParameter(ProjectRootElement projectXml, string unevaluatedPropertyValue)
            {
                (bool success, ProjectTaskElement execTask)result = FindExecTaskInTargets(projectXml);

                if (result.success == true)
                {
                    SetExecParameter(result.execTask, unevaluatedPropertyValue);
                }
                else
                {
                    ProjectTargetElement target = projectXml.AddTarget(TargetName);
                    SetTargetDependencies(target);
                    ProjectTaskElement execTask = target.AddTask(ExecTask);
                    SetExecParameter(execTask, unevaluatedPropertyValue);
                }
            }
        static public ProjectTaskElement GetScannerTask(Project project)
        {
            ProjectTargetElement target = project.Xml.Targets.FirstOrDefault(element => element.Name == "AfterBuild");

            if (target != null)
            {
                foreach (ProjectTaskElement task in target.Tasks)
                {
                    if (task != null && task.Name == "ScannerTask")
                    {
                        return(task);
                    }
                }
            }

            return(null);
        }
        static public Project SetupMSBuildProject(IList <string> filesToScan, IList <string> termTableFiles)
        {
            Project project       = SetupMSBuildProject();
            string  projectFolder = Path.GetDirectoryName(project.FullPath);

            if (filesToScan.Count > 0)
            {
                project.Xml.AddItem("ItemGroup1", CodeSweep.Utilities.RelativePathFromAbsolute(filesToScan[0], projectFolder));
                if (filesToScan.Count > 1)
                {
                    for (int i = 1; i < filesToScan.Count; ++i)
                    {
                        project.Xml.AddItem("ItemGroup2", CodeSweep.Utilities.RelativePathFromAbsolute(filesToScan[i], projectFolder));
                    }
                }
            }

            List <string> rootedTermTables   = new List <string>(termTableFiles);
            List <string> relativeTermTables = rootedTermTables.ConvertAll <string>(
                delegate(string rootedPath)
            {
                return(CodeSweep.Utilities.RelativePathFromAbsolute(rootedPath, projectFolder));
            });

            ProjectTargetElement target = project.Xml.AddTarget("AfterBuild");

            ProjectTaskElement newTask = target.AddTask("ScannerTask");

            newTask.Condition       = "'$(RunCodeSweepAfterBuild)' == 'true'";
            newTask.ContinueOnError = "false";
            newTask.SetParameter("FilesToScan", "@(ItemGroup1);@(ItemGroup2)");
            newTask.SetParameter("TermTables", CodeSweep.Utilities.Concatenate(relativeTermTables, ";"));
            newTask.SetParameter("Project", "$(MSBuildProjectFullPath)");

            string usingTaskAssembly = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetLoadedModules()[0].FullyQualifiedName) + "\\BuildTask.dll";

            project.Xml.AddUsingTask("CodeSweep.BuildTask.ScannerTask", usingTaskAssembly, null);

            ProjectPropertyGroupElement group = project.Xml.AddPropertyGroup();

            group.AddProperty("RunCodeSweepAfterBuild", "true");

            project.ReevaluateIfNecessary();
            return(project);
        }
        public void XmlLocationReflectsRename()
        {
            ProjectRootElement project = ProjectRootElement.Create();

            project.FullPath = "c:\\x";
            ProjectTargetElement target = project.CreateTargetElement("t");

            target.Outputs = "o";
            project.AppendChild(target);

            Assert.Equal(project.FullPath, target.Location.File);
            Assert.Equal(project.FullPath, target.OutputsLocation.File);

            project.FullPath = "c:\\y";

            Assert.Equal(project.FullPath, target.Location.File);
            Assert.Equal(project.FullPath, target.OutputsLocation.File);
        }
Esempio n. 28
0
        /// <summary>
        /// Create a build file that build the projects in the specified order
        /// </summary>
        /// <param name="buildFilePath"></param>
        /// <param name="projectList"></param>
        /// <returns></returns>
        public static bool CreateBuildFile(string buildFilePath, List <string> projectList)
        {
            ProjectRootElement proj = ProjectRootElement.Create(buildFilePath);

            proj.AddProperty("Configuration", "Release");
            proj.AddProperty("Platform", "x86");

            ProjectTargetElement trgt = proj.AddTarget("Build");

            foreach (string p in projectList)
            {
                ProjectTaskElement task = trgt.AddTask("MSBuild");
                task.SetParameter("Projects", p);
            }

            proj.Save();
            return(true);
        }
Esempio n. 29
0
 internal ProjectTargetInstance(ProjectTargetElement xml)
 {
     FullPath = xml.ContainingProject.FullPath;
     Children = xml.Children.Select <ProjectElement, ProjectTargetInstanceChild> (c => {
         if (c is ProjectOnErrorElement)
         {
             return(new ProjectOnErrorInstance((ProjectOnErrorElement)c));
         }
         if (c is ProjectItemGroupElement)
         {
             return(new ProjectItemGroupTaskInstance((ProjectItemGroupElement)c));
         }
         if (c is ProjectPropertyGroupElement)
         {
             return(new ProjectPropertyGroupTaskInstance((ProjectPropertyGroupElement)c));
         }
         if (c is ProjectTaskElement)
         {
             return(new ProjectTaskInstance((ProjectTaskElement)c));
         }
         throw new NotSupportedException();
     }).ToArray();
     Condition        = xml.Condition;
     DependsOnTargets = xml.DependsOnTargets;
     //FullPath = fullPath;
     Inputs = xml.Inputs;
     KeepDuplicateOutputs = xml.KeepDuplicateOutputs;
     Name            = xml.Name;
     OnErrorChildren = xml.OnErrors.Select(c => new ProjectOnErrorInstance(c)).ToArray();
     Outputs         = xml.Outputs;
     Returns         = xml.Returns;
     Tasks           = xml.Tasks.Select(t => new ProjectTaskInstance(t)).ToArray();
                 #if NET_4_5
     AfterTargetsLocation         = xml.AfterTargetsLocation;
     BeforeTargetsLocation        = xml.BeforeTargetsLocation;
     ConditionLocation            = xml.ConditionLocation;
     DependsOnTargetsLocation     = xml.DependsOnTargetsLocation;
     InputsLocation               = xml.InputsLocation;
     KeepDuplicateOutputsLocation = xml.KeepDuplicateOutputsLocation;
     Location        = xml.Location;
     OutputsLocation = xml.OutputsLocation;
     ReturnsLocation = xml.ReturnsLocation;
                 #endif
 }
Esempio n. 30
0
        /// <summary>
        /// Helper to get a ProjectOutputElement for an output property
        /// </summary>
        private static ProjectOutputElement GetOutputProperty()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t'>
                            <t1>
                                <Output TaskParameter='p' PropertyName='p1' />
                            </t1>
                            <t2/>
                        </Target>
                    </Project>
                ";

            ProjectRootElement   project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);
            ProjectTaskElement   task    = (ProjectTaskElement)Helpers.GetFirst(target.Children);

            return(Helpers.GetFirst(task.Outputs));
        }