示例#1
0
        public void GetBuildTaskWithCreation()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            // Create a project without a build task.
            Microsoft.Build.Evaluation.Project project = Utilities.SetupMSBuildProject();

            project.Xml.AddItem("foo", "blah.txt");
            project.Xml.AddItem("bar", "blah2.cs");
            project.Xml.AddItem("Reference", "My.Namespace.Etc");

            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            ProjectTaskElement task = accessor.GetBuildTask(vsProject, true);

            Assert.IsNotNull(task, "GetBuildTask did not create task.");
            Assert.AreEqual("false", task.ContinueOnError, "ContinueOnError is wrong.");
            Assert.AreEqual("Exists('" + Utilities.GetTargetsPath() + "') and '$(RunCodeSweepAfterBuild)' == 'true'", task.Condition, "Condition is wrong.");
            Assert.AreEqual("@(foo);@(bar)", task.GetParameter("FilesToScan"), "FilesToScan property is wrong.");
            Assert.AreEqual("$(MSBuildProjectFullPath)", task.GetParameter("Project"), "Project property is wrong.");

            string projectFolder     = Path.GetDirectoryName(project.FullPath);
            string expectedTermTable = CodeSweep.Utilities.RelativePathFromAbsolute(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\CodeSweep\\sample_term_table.xml", projectFolder);

            Assert.AreEqual(expectedTermTable, task.GetParameter("TermTables"), "TermTables property is wrong.");

            // Ensure the task is in the AfterBuild target.
            bool found = false;

            foreach (ProjectTaskElement thisTask in project.Xml.Targets.FirstOrDefault(target => target.Name == "AfterBuild").Tasks)
            {
                if (thisTask == task)
                {
                    found = true;
                    break;
                }
            }
            Assert.IsTrue(found, "The task was not in the AfterBuild target.");

            ProjectImportElement import = GetImport(project, Utilities.GetTargetsPath());

            Assert.IsNotNull(import, "GetBuildTask did not create Import.");
        }
        private void ReadConfigFromBuildTask()
        {
            string projectFolder = Path.GetDirectoryName(ProjectUtilities.GetProjectFilePath(_project));

            _ignoreInstances.AddRange(BuildTask.Factory.DeserializeIgnoreInstances(_buildTask.GetParameter("IgnoreInstances"), projectFolder));

            foreach (string termTable in _buildTask.GetParameter("TermTables").Split(';'))
            {
                if (termTable != null && termTable.Length > 0)
                {
                    if (Path.IsPathRooted(termTable))
                    {
                        _termTableFiles.Add(termTable);
                    }
                    else
                    {
                        _termTableFiles.Add(Utilities.AbsolutePathFromRelative(termTable, projectFolder));
                    }
                }
            }
        }
        public void ReadParameters()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t'>
                            <t1 p1='v1' p2='v2' />
                        </Target>
                    </Project>
                ";

            ProjectTaskElement task = GetTaskFromContent(content);

            var parameters = Helpers.MakeDictionary(task.Parameters);

            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual("v1", parameters["p1"]);
            Assert.AreEqual("v2", parameters["p2"]);

            Assert.AreEqual("v1", task.GetParameter("p1"));
            Assert.AreEqual(String.Empty, task.GetParameter("xxxx"));
        }
        public void ReadParameters()
        {
            string content = @"
                    <Project>
                        <Target Name='t'>
                            <t1 p1='v1' p2='v2' />
                        </Target>
                    </Project>
                ";

            ProjectTaskElement task = GetTaskFromContent(content);

            var parameters = Helpers.MakeDictionary(task.Parameters);

            Assert.Equal(2, parameters.Count);
            Assert.Equal("v1", parameters["p1"]);
            Assert.Equal("v2", parameters["p2"]);

            Assert.Equal("v1", task.GetParameter("p1"));
            Assert.Equal(String.Empty, task.GetParameter("xxxx"));
        }