Esempio n. 1
0
        void AddSolutionTargets(Project p, int num_levels, IEnumerable <ProjectInfo> websiteProjectInfos)
        {
            foreach (string buildTarget in buildTargets)
            {
                Target t = p.Targets.AddNewTarget(buildTarget);
                t.Condition = "'$(CurrentSolutionConfigurationContents)' != ''";

                BuildTask task = null;
                for (int i = 0; i < num_levels; i++)
                {
                    string level_str = String.Format("BuildLevel{0}", i);
                    task = t.AddNewTask("MSBuild");
                    task.SetParameterValue("Condition", String.Format("'@({0})' != ''", level_str));
                    task.SetParameterValue("Projects", String.Format("@({0})", level_str));
                    task.SetParameterValue("Properties",
                                           string.Format("Configuration=%(Configuration); Platform=%(Platform); BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)"));
                    if (buildTarget != "Build")
                    {
                        task.SetParameterValue("Targets", buildTarget);
                    }
                    //FIXME: change this to BuildInParallel=true, when parallel
                    //	 build support gets added
                    task.SetParameterValue("RunEachTargetSeparately", "true");

                    level_str      = String.Format("SkipLevel{0}", i);
                    task           = t.AddNewTask("Message");
                    task.Condition = String.Format("'@({0})' != ''", level_str);
                    task.SetParameterValue("Text",
                                           String.Format("The project '%({0}.Identity)' is disabled for solution " +
                                                         "configuration '$(Configuration)|$(Platform)'.", level_str));

                    level_str      = String.Format("MissingConfigLevel{0}", i);
                    task           = t.AddNewTask("Warning");
                    task.Condition = String.Format("'@({0})' != ''", level_str);
                    task.SetParameterValue("Text",
                                           String.Format("The project configuration for project '%({0}.Identity)' " +
                                                         "corresponding to the solution configuration " +
                                                         "'$(Configuration)|$(Platform)' was not found.", level_str));
                }

                // "build" website projects also
                StringBuilder w_targets = new StringBuilder();
                foreach (ProjectInfo info in websiteProjectInfos)
                {
                    if (w_targets.Length > 0)
                    {
                        w_targets.Append(";");
                    }
                    w_targets.Append(GetTargetNameForProject(info.Name, buildTarget));
                }

                task = t.AddNewTask("CallTarget");
                task.SetParameterValue("Targets", w_targets.ToString());
                task.SetParameterValue("RunEachTargetSeparately", "true");
            }
        }
Esempio n. 2
0
        void AddValidateSolutionConfiguration(Project p)
        {
            Target    t    = p.Targets.AddNewTarget("ValidateSolutionConfiguration");
            BuildTask task = t.AddNewTask("Error");

            task.SetParameterValue("Text", "Invalid solution configuration and platform: \"$(Configuration)|$(Platform)\".");
            task.Condition = "('$(CurrentSolutionConfigurationContents)' == '') and ('$(SkipInvalidConfigurations)' != 'true')";
            task           = t.AddNewTask("Warning");
            task.SetParameterValue("Text", "Invalid solution configuration and platform: \"$(Configuration)|$(Platform)\".");
            task.Condition = "('$(CurrentSolutionConfigurationContents)' == '') and ('$(SkipInvalidConfigurations)' == 'true')";
            task           = t.AddNewTask("Message");
            task.SetParameterValue("Text", "Building solution configuration \"$(Configuration)|$(Platform)\".");
            task.Condition = "'$(CurrentSolutionConfigurationContents)' != ''";
        }
Esempio n. 3
0
        public void AddNewTarget()
        {
            // The following code should create a project that effectively looks like this:
            //
            //      <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
            //          <Target Name="BuildMe">
            //              <Exec Command="echo foo"/>
            //          </Target>
            //      </Project>
            //
            myProject.DefaultTargets = "BuildMe";
            myProject.SetProperty("MyProp", "goober", null);
            Target    myTarget = myProject.Targets.AddNewTarget("BuildMe");
            BuildTask myTask   = myTarget.AddNewTask("Exec");

            myTask.SetParameterValue("Command", "echo $(MyProp)foo");

            // Build the project.
            myProject.Build("BuildMe");

            // Confirm the logger received what it was supposed to.
            Assertion.Assert(myLogger.FullLog.Contains("BuildMe"));
            Assertion.Assert(myLogger.FullLog.Contains("Exec"));
            Assertion.Assert(myLogger.FullLog.Contains("gooberfoo"));
        }
Esempio n. 4
0
        public void AddNewTargetWithOutputsString()
        {
            string targetOutputsString = @"@(SomeItem->'%(metadata)')";
            string targetInputsString  = null;

            BuildItem item1 = myProject.AddNewItem("SomeItem", "a");
            BuildItem item2 = myProject.AddNewItem("SomeItem", "b");

            item1.SetMetadata("metadata", "1");
            item2.SetMetadata("metadata", "2");

            myProject.DefaultTargets = "BuildMe";

            // Add a new target specifying the inputs and outputs attribute
            Target myTarget = myProject.Targets.AddNewTarget("BuildMe");

            myTarget.Inputs  = targetInputsString;
            myTarget.Outputs = targetOutputsString;

            BuildTask myTask = myTarget.AddNewTask("Exec");

            myTask.SetParameterValue("Command", "echo @(SomeItem)foo");

            ITaskItem[] outputItems = BuildAndGatherOutputs("BuildMe");

            // Confirm the logger received what it was supposed to.
            Assertion.Assert(myLogger.FullLog.Contains("BuildMe"));
            Assertion.Assert(myLogger.FullLog.Contains("Exec"));
            Assertion.Assert(myLogger.FullLog.Contains("a;bfoo"));
            Assertion.AssertEquals(outputItems[0].ToString(), "1");
            Assertion.AssertEquals(outputItems[1].ToString(), "2");
        }
Esempio n. 5
0
        public void AddNewTargetWithInputsString()
        {
            string targetInputsString  = "%(SomeItem.metadata)";
            string targetOutputsString = "target_output";

            BuildItem item1 = myProject.AddNewItem("SomeItem", "a");
            BuildItem item2 = myProject.AddNewItem("SomeItem", "b");

            item1.SetMetadata("metadata", "1");
            item2.SetMetadata("metadata", "2");

            myProject.DefaultTargets = "BuildMe";

            Target myTarget = myProject.Targets.AddNewTarget("BuildMe");

            myTarget.Inputs  = targetInputsString;
            myTarget.Outputs = targetOutputsString;

            BuildTask myTask = myTarget.AddNewTask("Exec");

            myTask.SetParameterValue("Command", "echo @(SomeItem)foo");

            myProject.Build("BuildMe");

            Assertion.Assert(myLogger.FullLog.Contains("BuildMe"));
            Assertion.Assert(myLogger.FullLog.Contains("Exec"));
            Assertion.Assert(myLogger.FullLog.Contains("afoo"));
            Assertion.Assert(myLogger.FullLog.Contains("bfoo"));
        }
Esempio n. 6
0
        void AddWebsiteResolveAndCopyReferencesTasks(Target target, ProjectInfo webProjectInfo,
                                                     string final_ref_item, string w_guid)
        {
            BuildTask task = target.AddNewTask("ResolveAssemblyReference");

            task.SetParameterValue("Assemblies", String.Format("@({0}->'%(FullPath)')", final_ref_item));
            task.SetParameterValue("TargetFrameworkDirectories", "$(TargetFrameworkPath)");
            task.SetParameterValue("SearchPaths", "{RawFileName};{TargetFrameworkDirectory};{GAC}");
            task.SetParameterValue("FindDependencies", "true");
            task.SetParameterValue("FindSatellites", "true");
            task.SetParameterValue("FindRelatedFiles", "true");
            task.Condition = String.Format("Exists ('%({0}.Identity)')", final_ref_item);

            string copylocal_item = String.Format("{0}_CopyLocalFiles", final_ref_item);

            task.AddOutputItem("CopyLocalFiles", copylocal_item);

            // Copy the references
            task = target.AddNewTask("Copy");
            task.SetParameterValue("SourceFiles", String.Format("@({0})", copylocal_item));
            task.SetParameterValue("DestinationFiles", String.Format(
                                       "@({0}->'$(Project_{1}_AspNetPhysicalPath)\\Bin\\%(DestinationSubDirectory)%(Filename)%(Extension)')",
                                       copylocal_item, w_guid));

            // AspNetConfiguration, is config for the website project, useful
            // for overriding from command line
            StringBuilder cond = new StringBuilder();

            foreach (string config in webProjectInfo.AspNetConfigurations)
            {
                if (cond.Length > 0)
                {
                    cond.Append(" or ");
                }
                cond.AppendFormat(" ('$(AspNetConfiguration)' == '{0}') ", config);
            }
            task.Condition = cond.ToString();

            task = target.AddNewTask("Message");
            cond = new StringBuilder();
            foreach (string config in webProjectInfo.AspNetConfigurations)
            {
                if (cond.Length > 0)
                {
                    cond.Append(" and ");
                }
                cond.AppendFormat(" ('$(AspNetConfiguration)' != '{0}') ", config);
            }
            task.Condition = cond.ToString();
            task.SetParameterValue("Text", "Skipping as the '$(AspNetConfiguration)' configuration is " +
                                   "not supported by this website project.");
        }
Esempio n. 7
0
        public void ChangingAnExistingTargetInputsAndOutputs()
        {
            string targetInputsString  = "%(SomeItem2.metadata)";
            string targetOutputsString = @"@(SomeItem2->'%(metadata)')";

            string projectContents = @"
                    <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                        <ItemGroup>
                            <SomeItem Include=""a"">
                                <metadata>1</metadata>
                            </SomeItem>
                            <SomeItem Include=""b"">
                                <metadata>2</metadata>
                            </SomeItem>
                            <SomeItem2 Include=""a2"">
                                <metadata>1-1</metadata>
                            </SomeItem2>
                            <SomeItem2 Include=""b2"">
                                <metadata>2-1</metadata>
                            </SomeItem2>
                        </ItemGroup>
                        <Target Name=""BuildMe"" Inputs=""%(SomeItem.metadata)"" Outputs=""@(SomeItem->'%(metadata)')"">
                            <Exec Command=""echo @(SomeItem)foo""/>
                        </Target>
                    </Project>
                ";

            myProject.LoadXml(projectContents);
            ITaskItem[] outputItems = BuildAndGatherOutputs("BuildMe");

            Assertion.Assert(myLogger.FullLog.Contains("afoo"));
            Assertion.Assert(myLogger.FullLog.Contains("bfoo"));
            Assertion.AssertEquals(outputItems[0].ToString(), "1");
            Assertion.AssertEquals(outputItems[1].ToString(), "2");

            ResetLogger();

            Target myTarget = GetTargetFromProject("BuildMe");

            myTarget.Inputs  = targetInputsString;
            myTarget.Outputs = targetOutputsString;

            BuildTask myTask = myTarget.AddNewTask("Exec");

            myTask.SetParameterValue("Command", "echo @(SomeItem2)foo");

            ITaskItem[] outputItems1 = BuildAndGatherOutputs("BuildMe");


            Assertion.Assert(myLogger.FullLog.Contains("a2foo"));
            Assertion.Assert(myLogger.FullLog.Contains("b2foo"));
            Assertion.AssertEquals(outputItems1[0].ToString(), "1-1");
            Assertion.AssertEquals(outputItems1[1].ToString(), "2-1");
        }
Esempio n. 8
0
        void AddWarningForMissingProjectConfiguration(Target target, string slnConfig, string slnPlatform, string projectName)
        {
            BuildTask task = target.AddNewTask("Warning");

            task.SetParameterValue("Text",
                                   String.Format("The project configuration for project '{0}' corresponding " +
                                                 "to the solution configuration '{1}|{2}' was not found in the solution file.",
                                                 projectName, slnConfig, slnPlatform));
            task.Condition = String.Format("('$(Configuration)' == '{0}') and ('$(Platform)' == '{1}')",
                                           slnConfig, slnPlatform);
        }
Esempio n. 9
0
        public void AddNewTaskSimpleTaskNameString()
        {
            project.LoadXml(ProjectContentsOneTarget);
            Target t = GetSpecificTargetFromProject(project, "t1");

            BuildTask task = t.AddNewTask("Message");

            task.SetParameterValue("Text", "t1.task");

            Assertion.AssertEquals(true, project.Build("t1"));
            Assertion.AssertEquals(true, logger.FullLog.Contains("t1.task"));
        }
Esempio n. 10
0
        public void AddNewTaskToATargetThatContainsAPreExistingTask()
        {
            project.LoadXml(ProjectContentOneTargetWithTask);
            Target    t    = GetSpecificTargetFromProject(project, "t1");
            BuildTask task = t.AddNewTask("Message");

            task.SetParameterValue("Text", "t1.task2");

            Assertion.AssertEquals(true, project.Build("t1"));
            Assertion.AssertEquals(true, logger.FullLog.Contains("t1.task1"));
            Assertion.AssertEquals(true, logger.FullLog.Contains("t1.task2"));
        }
Esempio n. 11
0
        void AddWebsiteUnsupportedTarget(Project p, ProjectInfo webProjectInfo, List <ProjectInfo> depInfos,
                                         string buildTarget)
        {
            Target target = p.Targets.AddNewTarget(GetTargetNameForProject(webProjectInfo.Name, buildTarget));

            target.DependsOnTargets = GetWebsiteDependsOnTarget(depInfos, buildTarget);

            BuildTask task = target.AddNewTask("Message");

            task.SetParameterValue("Text", String.Format(
                                       "Target '{0}' not support for website projects", buildTarget));
        }
Esempio n. 12
0
        // emits the MSBuild task to GetTargetPath for the referenced project
        void AddWebsiteMSBuildTaskForReference(Target target, ProjectInfo depInfo, TargetInfo projectTargetInfo,
                                               TargetInfo solutionTargetInfo, string final_ref_item, int ref_num)
        {
            BuildTask task = target.AddNewTask("MSBuild");

            task.SetParameterValue("Projects", depInfo.FileName);
            task.SetParameterValue("Targets", "GetTargetPath");

            task.SetParameterValue("Properties", string.Format("Configuration={0}; Platform={1}; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)", projectTargetInfo.Configuration, projectTargetInfo.Platform));
            task.Condition = string.Format(" ('$(Configuration)' == '{0}') and ('$(Platform)' == '{1}') ", solutionTargetInfo.Configuration, solutionTargetInfo.Platform);

            string ref_item = String.Format("{0}_{1}",
                                            final_ref_item, ref_num);

            task.AddOutputItem("TargetOutputs", ref_item);

            task = target.AddNewTask("CreateItem");
            task.SetParameterValue("Include", String.Format("@({0})", ref_item));
            task.SetParameterValue("AdditionalMetadata", String.Format("Guid={{{0}}}",
                                                                       depInfo.Guid.ToString().ToUpper()));
            task.AddOutputItem("Include", final_ref_item);
        }
Esempio n. 13
0
        public void RemoveTaskRemoveNewlyAddedTask()
        {
            project.LoadXml(ProjectContentsOneTarget);
            Target    t    = GetSpecificTargetFromProject(project, "t1");
            BuildTask task = t.AddNewTask("Message");

            task.SetParameterValue("Text", "t1.task1");

            t.RemoveTask(task);

            Assertion.AssertEquals(true, project.Build("t1"));
            Assertion.AssertEquals(false, logger.FullLog.Contains("t1.task1"));
        }
Esempio n. 14
0
        private void AddContentBuildTask(string intermediateDirectory, string outputDirectory, string rootDirectory, string targetPlatform)
        {
            BuildTask contentTask = m_contentTarget.AddNewTask("CreateItem");

            contentTask.SetParameterValue("Include", "@(Content)");
            contentTask.Condition = "'%(Content.Importer)' != 'XactImporter'";
            contentTask.AddOutputItem("Include", "XNAContent");

            BuildTask bt = m_xnaTarget.AddNewTask("BuildContent");

            bt.SetParameterValue("SourceAssets", "@(XNAContent)");
            bt.SetParameterValue("PipelineAssemblies", "@(PipelineAssembly)");
            bt.SetParameterValue("IntermediateDirectory", intermediateDirectory);
            bt.SetParameterValue("OutputDirectory", outputDirectory);
            bt.SetParameterValue("RootDirectory", rootDirectory);
            bt.SetParameterValue("TargetPlatform", targetPlatform);
        }
Esempio n. 15
0
        private void AddXActBuildTask(string intermediateDirectory, string outputDirectory, string rootDirectory, string targetPlatform)
        {
            BuildTask xactTask = m_contentTarget.AddNewTask("CreateItem");

            xactTask.SetParameterValue("Include", "@(Content)");
            xactTask.Condition = "'%(Content.Importer)' == 'XactImporter'";
            xactTask.AddOutputItem("Include", "XACTContent");

            BuildTask bt = m_xnaTarget.AddNewTask("BuildXact");

            bt.SetParameterValue("XactProjects", "@(XACTContent)");
            bt.SetParameterValue("IntermediateDirectory", intermediateDirectory);
            bt.SetParameterValue("OutputDirectory", outputDirectory);
            bt.SetParameterValue("RootDirectory", rootDirectory);
            bt.SetParameterValue("TargetPlatform", targetPlatform);
            bt.SetParameterValue("XnaFrameworkVersion", "v1.0");
        }
Esempio n. 16
0
        public void AddNewTaskSaveProjectAfterSet()
        {
            project.LoadXml(ProjectContentsOneTarget);
            Target t = GetSpecificTargetFromProject(project, "t1");

            BuildTask task = t.AddNewTask("Message");

            task.SetParameterValue("Text", "t1.task");

            string expectedProjectContents = @"
                                            <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
                                                <Target Name='t1'>
                                                    <Message Text='t1.task'/>
                                                </Target>
                                            </Project>
                                        ";

            SaveProjectToDiskAndCompareAgainstExpectedContents(project, expectedProjectContents);
        }
Esempio n. 17
0
        void AddProjectTargets(Project p, List <TargetInfo> solutionTargets, Dictionary <Guid, ProjectInfo> projectInfos)
        {
            foreach (KeyValuePair <Guid, ProjectInfo> projectInfo in projectInfos)
            {
                ProjectInfo project = projectInfo.Value;
                foreach (string buildTarget in buildTargets)
                {
                    string target_name = GetTargetNameForProject(project.Name, buildTarget);
                    Target target      = p.Targets.AddNewTarget(target_name);
                    target.Condition = "'$(CurrentSolutionConfigurationContents)' != ''";

                    if (project.Dependencies.Count > 0)
                    {
                        StringBuilder dependencies = new StringBuilder();
                        foreach (ProjectInfo dependentInfo in project.Dependencies.Values)
                        {
                            if (dependencies.Length > 0)
                            {
                                dependencies.Append(";");
                            }
                            if (IsBuildTargetName(dependentInfo.Name))
                            {
                                dependencies.Append("Solution:");
                            }
                            dependencies.Append(dependentInfo.Name);
                            if (buildTarget != "Build")
                            {
                                dependencies.Append(":" + buildTarget);
                            }
                        }
                        target.DependsOnTargets = dependencies.ToString();
                    }

                    foreach (TargetInfo targetInfo in solutionTargets)
                    {
                        BuildTask  task = null;
                        TargetInfo projectTargetInfo;
                        if (!project.TargetMap.TryGetValue(targetInfo, out projectTargetInfo))
                        {
                            AddWarningForMissingProjectConfiguration(target, targetInfo.Configuration,
                                                                     targetInfo.Platform, project.Name);
                            continue;
                        }
                        if (projectTargetInfo.Build)
                        {
                            task = target.AddNewTask("MSBuild");
                            task.SetParameterValue("Projects", project.FileName);

                            if (buildTarget != "Build")
                            {
                                task.SetParameterValue("Targets", buildTarget);
                            }
                            task.SetParameterValue("Properties", string.Format("Configuration={0}; Platform={1}; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)", projectTargetInfo.Configuration, projectTargetInfo.Platform));
                        }
                        else
                        {
                            task = target.AddNewTask("Message");
                            task.SetParameterValue("Text", string.Format("Project \"{0}\" is disabled for solution configuration \"{1}|{2}\".", project.Name, targetInfo.Configuration, targetInfo.Platform));
                        }
                        task.Condition = string.Format(" ('$(Configuration)' == '{0}') and ('$(Platform)' == '{1}') ", targetInfo.Configuration, targetInfo.Platform);
                    }
                }
            }
        }