当前位置: 首页>>代码示例>>C#>>正文


C# Target.AddNewTask方法代码示例

本文整理汇总了C#中Microsoft.Build.BuildEngine.Target.AddNewTask方法的典型用法代码示例。如果您正苦于以下问题:C# Target.AddNewTask方法的具体用法?C# Target.AddNewTask怎么用?C# Target.AddNewTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Build.BuildEngine.Target的用法示例。


在下文中一共展示了Target.AddNewTask方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StringBuilder

        /// <summary>
        /// Adds tasks that create a temporary VC project file with pre-resolved project references (that is,
        /// replaced with file references)
        /// </summary>
        /// <param name="solution"></param>
        /// <param name="target"></param>
        /// <param name="proj"></param>
        /// <param name="solutionConfiguration"></param>
        /// <param name="subTargetName"></param>
        /// <param name="projectConfigurationName"></param>
        /// <returns>The path to the temporary project file</returns>
        /// <owner>LukaszG</owner>
        static private string AddCreateTemporaryVCProjectTasks
        (
            SolutionParser solution,
            Project msbuildProject,
            Target target,
            ProjectInSolution proj,
            ConfigurationInSolution solutionConfiguration,
            string subTargetName,
            string projectConfigurationName
        )
        {
            StringBuilder referenceItemName = new StringBuilder(GenerateSafePropertyName(proj, "References"));
            if (!string.IsNullOrEmpty(subTargetName))
            {
                referenceItemName.Append('_');
                referenceItemName.Append(subTargetName);
            }

            StringBuilder importLibraryItemName = new StringBuilder(GenerateSafePropertyName(proj, "ImportLibraries"));
            if (!string.IsNullOrEmpty(subTargetName))
            {
                importLibraryItemName.Append('_');
                importLibraryItemName.Append(subTargetName);
            }

            string referenceGuidsToRemove = null;

            AddResolveProjectReferenceTasks(solution, msbuildProject, target, proj, solutionConfiguration,
                referenceItemName.ToString(), importLibraryItemName.ToString(), out referenceGuidsToRemove);

            if (string.IsNullOrEmpty(referenceGuidsToRemove))
                referenceGuidsToRemove = string.Empty;

            string fullProjectPath = null;
            string tmpExtension = null;
            string projectPath = null;

            try
            {
                fullProjectPath = proj.AbsolutePath;
                tmpExtension = string.Format(CultureInfo.InvariantCulture, ".tmp_{0}_{1}.vcproj", solutionConfiguration.ConfigurationName, solutionConfiguration.PlatformName);
                projectPath = Path.ChangeExtension(fullProjectPath, tmpExtension);
            }
            catch (Exception e)
            {
                if (ExceptionHandling.NotExpectedException(e))
                    throw;

                ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(false,
                    "SubCategoryForSolutionParsingErrors",
                    new BuildEventFileInfo(solution.SolutionFile),
                    "SolutionParseInvalidProjectFileName",
                    proj.RelativePath, e.Message);
            }


            // Create the temporary VC project
            BuildTask createVCProjectTask = target.AddNewTask("CreateTemporaryVCProject");
            createVCProjectTask.SetParameterValue("ProjectFile", fullProjectPath, true /* treat as literal */);
            createVCProjectTask.SetParameterValue("Configuration", projectConfigurationName, true /* treat as literal */);
            createVCProjectTask.SetParameterValue("OutputProjectFile", projectPath, true /* treat as literal */);

            createVCProjectTask.SetParameterValue("ReferenceGuids", referenceGuidsToRemove, false /* Contains semicolon-separated list.  DO NOT treat as literal */);
            createVCProjectTask.SetParameterValue("ReferenceAssemblies",
                string.Format(CultureInfo.InvariantCulture, "@({0})", referenceItemName.ToString()), false /* DO NOT treat as literal */);
            createVCProjectTask.SetParameterValue("ReferenceImportLibraries",
                string.Format(CultureInfo.InvariantCulture, "@({0})", importLibraryItemName.ToString()), false /* DO NOT treat as literal */);

            createVCProjectTask.Condition = GetConditionStringForConfiguration(solutionConfiguration);

            return projectPath;
        }
开发者ID:nikson,项目名称:msbuild,代码行数:84,代码来源:SolutionWrapperProject.cs

示例2:

        /// <summary>
        /// Adds a new ResolveVCProjectOutput task element to the specified target
        /// </summary>
        /// <param name="target"></param>
        /// <param name="solutionPath"></param>
        /// <param name="projectPath"></param>
        /// <param name="fullConfigurationName"></param>
        /// <returns></returns>
        /// <owner>LukaszG</owner>
        static private BuildTask AddResolveVCProjectOutputTaskElement
        (
            Target target,
            string solutionPath,
            string projectPath,
            string fullConfigurationName
        )
        {
            BuildTask newTask = target.AddNewTask("ResolveVCProjectOutput");

            newTask.SetParameterValue("ProjectReferences", projectPath, true /* treat as literal */);
            newTask.SetParameterValue("Configuration", fullConfigurationName, true /* treat as literal */);
            newTask.SetParameterValue("SolutionFile", solutionPath, true /* treat as literal */);

            // If the user passed in an override stylesheet for this .VCPROJ (by specifying a global
            // property called VCBuildOverride), we need to use it to resolve the output path.  Override 
            // stylesheets can be used to change the directory that VC projects get built to.
            newTask.SetParameterValue("Override", "$(VCBuildOverride)");

            return newTask;
        }
开发者ID:nikson,项目名称:msbuild,代码行数:30,代码来源:SolutionWrapperProject.cs

示例3: AddErrorWarningMessageElement

        /// <summary>
        /// Add a new error/warning/message tag into the given target
        /// </summary>
        /// <param name="target">Destination target for the tag</param>
        /// <param name="elementType">Element type to add (Error, Warning, Message)</param>
        /// <param name="treatAsLiteral">Whether to treat the Text as a literal string or one that contains embedded properties, etc.</param>
        /// <param name="textResourceName">Resource string name to use in the tag text</param>
        /// <param name="args">Additional parameters to pass to FormatString</param>
        /// <owner>LukaszG</owner>
        static internal BuildTask AddErrorWarningMessageElement(Target target, string elementType, 
            bool treatAsLiteral, string textResourceName, params object[] args)
        {
            string code = null;
            string helpKeyword = null;
            string text = ResourceUtilities.FormatResourceString(out code, out helpKeyword, textResourceName, args);

            BuildTask task = target.AddNewTask(elementType);
            task.SetParameterValue("Text", text, treatAsLiteral);

            if ((elementType != XMakeElements.message) && (code != null))
            {
                task.SetParameterValue("Code", code, true /* treat as literal */);
            }

            if ((elementType != XMakeElements.message) && (helpKeyword != null))
            {
                task.SetParameterValue("HelpKeyword", helpKeyword, true /* treat as literal */);
            }

            return task;
        }
开发者ID:nikson,项目名称:msbuild,代码行数:31,代码来源:SolutionWrapperProject.cs

示例4: GenerateSafePropertyName

        /// <summary>
        /// This code handles the *.REFRESH files that are in the "bin" subdirectory of 
        /// a web project.  These .REFRESH files are just text files that contain absolute or 
        /// relative paths to the referenced assemblies.  The goal of these tasks is to 
        /// search all *.REFRESH files and extract fully-qualified absolute paths for 
        /// each of the references.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="proj"></param>
        /// <param name="referenceItemName"></param>
        /// <owner>RGoel</owner>
        static private void AddTasksToResolveAutoRefreshFileReferences
            (
            Target target, 
            ProjectInSolution proj, 
            string referenceItemName
            )
        {
            string webRoot = "$(" + GenerateSafePropertyName(proj, "AspNetPhysicalPath") + ")";

            // Create an item list containing each of the .REFRESH files.
            BuildTask createItemTask = target.AddNewTask("CreateItem");
            createItemTask.SetParameterValue("Include", webRoot + @"\Bin\*.refresh");
            createItemTask.AddOutputItem("Include", referenceItemName + "_RefreshFile");

            // Read the lines out of each .REFRESH file; they should be paths to .DLLs.  Put these paths
            // into an item list.
            BuildTask readLinesTask = target.AddNewTask("ReadLinesFromFile");
            readLinesTask.SetParameterValue("File", 
                String.Format(CultureInfo.InvariantCulture, @"%({0}_RefreshFile.Identity)", referenceItemName));
            readLinesTask.Condition = String.Format(CultureInfo.InvariantCulture, @" '%({0}_RefreshFile.Identity)' != '' ", referenceItemName);
            readLinesTask.AddOutputItem("Lines", referenceItemName + "_ReferenceRelPath");

            // Take those paths and combine them with the root of the web project to form either
            // an absolute path or a path relative to the .SLN file.  These paths can be passed
            // directly to RAR later.
            BuildTask combinePathTask = target.AddNewTask("CombinePath");
            combinePathTask.SetParameterValue("BasePath", webRoot);
            combinePathTask.SetParameterValue("Paths", 
                String.Format(CultureInfo.InvariantCulture, @"@({0}_ReferenceRelPath)", referenceItemName));
            combinePathTask.AddOutputItem("CombinedPaths", referenceItemName);
        }
开发者ID:nikson,项目名称:msbuild,代码行数:42,代码来源:SolutionWrapperProject.cs

示例5:

        /// <summary>
        /// Adds a new VCBuild task element to the specified target
        /// </summary>
        /// <param name="target">The target to add the VCBuild task to</param>
        /// <param name="solutionPath">Path to the solution if any</param>
        /// <param name="projectPath">Path to the solution if any</param>
        /// <param name="vcbuildTargetName">The VCBuild target name</param>
        /// <param name="platformName">The platform parameter to VCBuild</param>
        /// <param name="fullConfigurationName">Configuration property value</param>
        /// <returns></returns>
        static internal BuildTask AddVCBuildTaskElement
        (
            Project msbuildProject,
            Target target,
            string solutionPath,
            string projectPath,
            string vcbuildTargetName,
            string platformName,
            string fullConfigurationName
        )
        {
            // The VCBuild task (which we already shipped) has a bug - it cannot
            // find vcbuild.exe when running in MSBuild 64 bit unless it's on the path.
            // So, pass it here, unless some explicit path was passed.
            // Note, we have to do this even if we're in a 32 bit MSBuild, because we save the .sln.cache
            // file, and the next build of the solution could be a 64 bit MSBuild.

            if (VCBuildLocationHint != null) // Should only be null if vcbuild truly isn't installed; in that case, let the task log its error
            {
                BuildTask createProperty = target.AddNewTask("CreateProperty");

                createProperty.SetParameterValue("Value", VCBuildLocationHint);
                createProperty.Condition = "'$(VCBuildToolPath)' == ''";
                createProperty.AddOutputProperty("Value", "VCBuildToolPath");
            }

            BuildTask newTask = target.AddNewTask("VCBuild");

            newTask.SetParameterValue("Projects", projectPath, true /* treat as literal */);

            // Add the toolpath so that the user can override if necessary
            newTask.SetParameterValue("ToolPath", "$(VCBuildToolPath)");

            newTask.SetParameterValue("Configuration", fullConfigurationName);

            if (!string.IsNullOrEmpty(platformName))
            {
                newTask.SetParameterValue("Platform", platformName);
            }

            newTask.SetParameterValue("SolutionFile", solutionPath);

            if ((vcbuildTargetName != null) && (vcbuildTargetName.Length > 0))
            {
                newTask.SetParameterValue(vcbuildTargetName, "true");
            }

            // Add the override switch so that the user can supply one if necessary
            newTask.SetParameterValue("Override", "$(VCBuildOverride)");

            // Add any additional lib paths
            newTask.SetParameterValue("AdditionalLibPaths", "$(VCBuildAdditionalLibPaths)");

            // Only use new properties if we're not emitting a 2.0 project
            if (!String.Equals(msbuildProject.ToolsVersion, "2.0", StringComparison.OrdinalIgnoreCase))
            {
                // Add any additional link library paths
                newTask.SetParameterValue("AdditionalLinkLibraryPaths", "$(VCBuildAdditionalLinkLibraryPaths)");

                // Add the useenv switch so that the user can supply one if necessary
                // Note: "VCBuildUserEnvironment" is included for backwards-compatibility; the correct
                // property name is "VCBuildUseEnvironment" to match the task parameter. When the old name is
                // used the task will emit a warning.
                newTask.SetParameterValue("UseEnvironment", "$(VCBuildUseEnvironment)");
            }

            newTask.SetParameterValue("UserEnvironment", "$(VCBuildUserEnvironment)");

            // Add the additional options switches
            newTask.SetParameterValue("AdditionalOptions", "$(VCBuildAdditionalOptions)");

            return newTask;
        }
开发者ID:nikson,项目名称:msbuild,代码行数:83,代码来源:VCWrapperProject.cs

示例6: CreateNewTaskOnTarget

        /*/// <summary>
        /// Gets or sets the default source parameter identifier.
        /// </summary>
        /// <value>The default source parameter identifier.</value>
        public string DefaultSourceParameterIdentifier
        {
            get
            {
                return this.defaultSourceParameterIdentifier;
            }

            set
            {
                this.defaultSourceParameterIdentifier = value;
            }
        }*/
        /// <summary>
        /// Creates and Adds a new task on a build target.
        /// </summary>
        /// <param name="target">The build target.</param>
        /// <param name="sourceParameterIdentifier">The source parameter identifier used to name the
        /// ItemGroup with source files.</param>
        /// <param name="sourceParameter">The source parameter.</param>
        /// <returns>
        /// A new task ready to use.
        /// </returns>
        public BuildTask CreateNewTaskOnTarget(
            Target target,
            string sourceParameterIdentifier,
            string sourceParameter)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            // Compose the new task.
            var batask = target.AddNewTask(this.taskType.FullName);

            // Set the main source parameter on the build task.
            //batask.SetParameterValue(sourceParameter, this.DefaultSourceParameterIdentifier);
            var spi = @"@(" + sourceParameterIdentifier + ")";
            batask.SetParameterValue(sourceParameter, spi);

            // Store for later use with SetParametersOnCreatedTask( ... ).
            this.composedTask = batask;
            return batask;
        }
开发者ID:Jedzia,项目名称:BackBock,代码行数:48,代码来源:TaskComposer.cs


注:本文中的Microsoft.Build.BuildEngine.Target.AddNewTask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。