AddNewTask() private method

private AddNewTask ( string taskName ) : Microsoft.Build.BuildEngine.BuildTask
taskName string
return Microsoft.Build.BuildEngine.BuildTask
Esempio n. 1
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. 2
0
        /// <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;
        }
Esempio n. 3
0
        /// <summary>
        /// Adds MSBuild and ResolveVCProjectOutput tasks to a project target to pre-resolve its project references
        /// </summary>
        /// <param name="solution"></param>
        /// <param name="target"></param>
        /// <param name="proj"></param>
        /// <param name="solutionConfiguration"></param>
        /// <param name="outputReferenceItemName"></param>
        /// <param name="outputImportLibraryItemName"></param>
        /// <param name="addedReferenceGuids"></param>
        /// <owner>LukaszG</owner>
        static private void AddResolveProjectReferenceTasks
        (
            SolutionParser solution,
            Project msbuildProject,
            Target target,
            ProjectInSolution proj,
            ConfigurationInSolution solutionConfiguration,
            string outputReferenceItemName,
            string outputImportLibraryItemName,
            out string addedReferenceGuids
        )
        {
            StringBuilder referenceGuids = new StringBuilder();

            string message = null;

            // Suffix for the reference item name. Since we need to attach additional (different) metadata to every
            // reference item, we need to have helper item lists each with only one item
            int outputReferenceItemNameSuffix = 0;

            // Pre-resolve the MSBuild/VC project references
            foreach (string projectReferenceGuid in proj.ProjectReferences)
            {
                ProjectInSolution referencedProject = (ProjectInSolution)solution.ProjectsByGuid[projectReferenceGuid];
                ProjectConfigurationInSolution referencedProjectConfiguration = null;

                if ((referencedProject != null) &&
                    (referencedProject.ProjectConfigurations.TryGetValue(solutionConfiguration.FullName, out referencedProjectConfiguration)) &&
                    (referencedProjectConfiguration != null))
                {
                    string outputReferenceItemNameWithSuffix = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", 
                        outputReferenceItemName, outputReferenceItemNameSuffix);

                    bool addCreateItem = false;

                    if ((referencedProject.ProjectType == SolutionProjectType.ManagedProject) ||
                        ((referencedProject.ProjectType == SolutionProjectType.Unknown) && (referencedProject.CanBeMSBuildProjectFile(out message))))
                    {
                        string condition = GetConditionStringForConfiguration(solutionConfiguration);
                        bool specifyProjectToolsVersion =
                            String.Equals(msbuildProject.ToolsVersion, "2.0", StringComparison.OrdinalIgnoreCase) ? false : true;

                        BuildTask msbuildTask = AddMSBuildTaskElement(target, referencedProject.RelativePath, "GetTargetPath",
                            referencedProjectConfiguration.ConfigurationName, referencedProjectConfiguration.PlatformName, specifyProjectToolsVersion);
                        msbuildTask.Condition = condition;
                        msbuildTask.AddOutputItem("TargetOutputs", outputReferenceItemNameWithSuffix);                        

                        if (referenceGuids.Length > 0)
                        {
                            referenceGuids.Append(';');
                        }

                        referenceGuids.Append(projectReferenceGuid);
                        addCreateItem = true;

                    }
                    else if (referencedProject.ProjectType == SolutionProjectType.VCProject)
                    {
                        BuildTask vcbuildTask = null;

                        try
                        {
                            vcbuildTask = AddResolveVCProjectOutputTaskElement(target, Path.Combine(solution.SolutionFileDirectory, Path.GetFileName(solution.SolutionFile)),
                                referencedProject.AbsolutePath, referencedProjectConfiguration.FullName);
                        }
                        catch (Exception e)
                        {
                            if (ExceptionHandling.NotExpectedException(e))
                               throw;

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

                        vcbuildTask.Condition = GetConditionStringForConfiguration(solutionConfiguration);
                        vcbuildTask.AddOutputItem("ResolvedOutputPaths", outputReferenceItemNameWithSuffix);
                        
                        if (outputImportLibraryItemName != null)
                        {
                            vcbuildTask.AddOutputItem("ResolvedImportLibraryPaths", outputImportLibraryItemName);
                        }

                        if (referenceGuids.Length > 0)
                        {
                            referenceGuids.Append(';');
                        }

                        referenceGuids.Append(projectReferenceGuid);
                        addCreateItem = true;
                    }

                    // Add create item if either of the conditions above was true. 
                    // This merges the one-item item list into the main list, adding the appropriate guid metadata
                    if (addCreateItem)
                    {
                        BuildTask createItemTask = target.AddNewTask("CreateItem");
                        createItemTask.SetParameterValue("Include", "@(" + outputReferenceItemNameWithSuffix + ")", false /* do not treat as literal */);
                        createItemTask.SetParameterValue("AdditionalMetadata", "Guid=" + projectReferenceGuid, false /* do not treat as literal */);
                        createItemTask.AddOutputItem("Include", outputReferenceItemName);
                    }

                    outputReferenceItemNameSuffix++;
                }
            }

            addedReferenceGuids = referenceGuids.ToString();
        }
Esempio n. 4
0
        /// <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;
        }
Esempio n. 5
0
        /// <summary>
        /// Adds an MSBuild task to the specified target
        /// </summary>
        /// <param name="target"></param>
        /// <param name="projectPath"></param>
        /// <param name="msbuildTargetName"></param>
        /// <param name="configurationName"></param>
        /// <param name="platformName"></param>
        /// <returns></returns>
        /// <owner>RGoel, LukaszG</owner>
        static private BuildTask AddMSBuildTaskElement
        (
            Target target, 
            string projectPath,
            string msbuildTargetName, 
            string configurationName, 
            string platformName,
            bool specifyProjectToolsVersion
        )
        {
            BuildTask newTask = target.AddNewTask("MSBuild");
            newTask.SetParameterValue("Projects", projectPath, true /* treat as literal */);

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

            string additionalProperties = string.Format(
                CultureInfo.InvariantCulture,
                "Configuration={0}; Platform={1}; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)",
                EscapingUtilities.Escape(configurationName),
                EscapingUtilities.Escape(platformName)
            );

            newTask.SetParameterValue("Properties", additionalProperties);
            if (specifyProjectToolsVersion)
            {
                newTask.SetParameterValue("ToolsVersion", "$(ProjectToolsVersion)");
                newTask.SetParameterValue("UnloadProjectsOnCompletion", "$(UnloadProjectsOnCompletion)");
                newTask.SetParameterValue("UseResultsCache", "$(UseResultsCache)");
            }

            return newTask;
        }
Esempio n. 6
0
        /// <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;
        }
Esempio n. 7
0
        /// <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);
        }
Esempio n. 8
0
        /// <summary>
        /// Add a call to the ResolveAssemblyReference task to crack the pre-resolved referenced 
        /// assemblies for the complete list of dependencies, PDBs, satellites, etc.  The invoke
        /// the Copy task to copy all these files (or at least the ones that RAR determined should
        /// be copied local) into the web project's bin directory.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="proj"></param>
        /// <param name="referenceItemName"></param>
        /// <param name="conditionDescribingValidConfigurations"></param>
        /// <owner>RGoel</owner>
        static private void AddTasksToCopyAllDependenciesIntoBinDir
            (
            Target target, 
            ProjectInSolution proj, 
            string referenceItemName, 
            string conditionDescribingValidConfigurations
            )
        {
            string copyLocalFilesItemName = referenceItemName + "_CopyLocalFiles";
            string destinationFolder = String.Format(CultureInfo.InvariantCulture,
                @"$({0})\Bin\", GenerateSafePropertyName(proj, "AspNetPhysicalPath"));

            // This is a bit of a hack.  We're actually calling the "Copy" task on all of 
            // the *non-existent* files.  Why?  Because we want to emit a warning in the 
            // log for each non-existent file, and the Copy task does that nicely for us.
            // I would have used the <Warning> task except for the fact that we are in 
            // string-resource lockdown.
            BuildTask copyNonExistentReferencesTask = target.AddNewTask("Copy");
            copyNonExistentReferencesTask.SetParameterValue("SourceFiles", "@(" + referenceItemName + "->'%(FullPath)')", false /* Do not treat as literal */);
            copyNonExistentReferencesTask.SetParameterValue("DestinationFolder", destinationFolder);
            copyNonExistentReferencesTask.Condition = String.Format(CultureInfo.InvariantCulture, "!Exists('%({0}.Identity)')", referenceItemName);
            copyNonExistentReferencesTask.ContinueOnError = true;

            // Call ResolveAssemblyReference on each of the .DLL files that were found on 
            // disk from the .REFRESH files as well as the P2P references.  RAR will crack
            // the dependencies, find PDBs, satellite assemblies, etc., and determine which
            // files need to be copy-localed.
            BuildTask rarTask = target.AddNewTask("ResolveAssemblyReference");
            rarTask.SetParameterValue("Assemblies", "@(" + referenceItemName + "->'%(FullPath)')", false /* Do not treat as literal */);
            rarTask.SetParameterValue("TargetFrameworkDirectories", "@(_CombinedTargetFrameworkDirectoriesItem)", false /* Do not treat as literal */);
            rarTask.SetParameterValue("InstalledAssemblyTables", "@(InstalledAssemblyTables)", false /* Do not treat as literal */);
            rarTask.SetParameterValue("SearchPaths", "{RawFileName};{TargetFrameworkDirectory};{GAC}");
            rarTask.SetParameterValue("FindDependencies", "true");
            rarTask.SetParameterValue("FindSatellites", "true");
            rarTask.SetParameterValue("FindSerializationAssemblies", "true");
            rarTask.SetParameterValue("FindRelatedFiles", "true");
            rarTask.Condition = String.Format(CultureInfo.InvariantCulture, "Exists('%({0}.Identity)')", referenceItemName);
            rarTask.AddOutputItem("CopyLocalFiles", copyLocalFilesItemName);

            // Copy all the copy-local files (reported by RAR) to the web project's "bin"
            // directory.
            BuildTask copyTask = target.AddNewTask("Copy");
            copyTask.SetParameterValue("SourceFiles", "@(" + copyLocalFilesItemName + ")", false /* DO NOT treat as literal */);
            copyTask.SetParameterValue("DestinationFiles", String.Format(CultureInfo.InvariantCulture,
                @"@({0}->'{1}%(DestinationSubDirectory)%(Filename)%(Extension)')", 
                copyLocalFilesItemName, destinationFolder), false /* DO NOT treat as literal */);
            copyTask.Condition = conditionDescribingValidConfigurations;
        }
Esempio n. 9
0
        /// <summary>
        /// Helper method to add a call to the AspNetCompiler task into the given target.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="proj"></param>
        /// <param name="conditionDescribingValidConfigurations"></param>
        /// <owner>RGoel</owner>
        static private void AddTaskForAspNetCompiler
            (
            Target target,
            ProjectInSolution proj,
            string conditionDescribingValidConfigurations
            )
        {
            // Add a call to the AspNetCompiler task, conditioned on having a valid Configuration.
            BuildTask newTask = target.AddNewTask("AspNetCompiler");
            newTask.SetParameterValue("VirtualPath", "$(" + GenerateSafePropertyName(proj, "AspNetVirtualPath") + ")");
            newTask.SetParameterValue("PhysicalPath", "$(" + GenerateSafePropertyName(proj, "AspNetPhysicalPath") + ")");
            newTask.SetParameterValue("TargetPath", "$(" + GenerateSafePropertyName(proj, "AspNetTargetPath") + ")");
            newTask.SetParameterValue("Force", "$(" + GenerateSafePropertyName(proj, "AspNetForce") + ")");
            newTask.SetParameterValue("Updateable", "$(" + GenerateSafePropertyName(proj, "AspNetUpdateable") + ")");
            newTask.SetParameterValue("Debug", "$(" + GenerateSafePropertyName(proj, "AspNetDebug") + ")");
            newTask.SetParameterValue("KeyFile", "$(" + GenerateSafePropertyName(proj, "AspNetKeyFile") + ")");
            newTask.SetParameterValue("KeyContainer", "$(" + GenerateSafePropertyName(proj, "AspNetKeyContainer") + ")");
            newTask.SetParameterValue("DelaySign", "$(" + GenerateSafePropertyName(proj, "AspNetDelaySign") + ")");
            newTask.SetParameterValue("AllowPartiallyTrustedCallers", "$(" + GenerateSafePropertyName(proj, "AspNetAPTCA") + ")");
            newTask.SetParameterValue("FixedNames", "$(" + GenerateSafePropertyName(proj, "AspNetFixedNames") + ")");

            newTask.Condition = conditionDescribingValidConfigurations;
        }
Esempio n. 10
0
        /// <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;
        }
Esempio n. 11
0
        /// <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);
        }
Esempio n. 12
0
        /*/// <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;
        }