示例#1
0
        /// <summary>
        /// This constructor allows all output data to be initialized.
        /// </summary>
        /// <owner>SumedhK</owner>
        /// <param name="node">The XML element for the Output tag.</param>
        internal TaskOutput(XmlElement node)
        {
            ErrorUtilities.VerifyThrow(node != null, "Need the XML for the <Output> tag.");

            ProjectXmlUtilities.VerifyThrowProjectNoChildElements(node);

            int    requiredData = 0;
            string taskName     = node.ParentNode.Name;

            foreach (XmlAttribute outputAttribute in node.Attributes)
            {
                switch (outputAttribute.Name)
                {
                case XMakeAttributes.taskParameter:
                    ProjectErrorUtilities.VerifyThrowInvalidProject(outputAttribute.Value.Length > 0, outputAttribute,
                                                                    "InvalidAttributeValue", outputAttribute.Value, outputAttribute.Name, XMakeElements.output);
                    ProjectErrorUtilities.VerifyThrowInvalidProject(!XMakeAttributes.IsSpecialTaskAttribute(outputAttribute.Value) && !XMakeAttributes.IsBadlyCasedSpecialTaskAttribute(outputAttribute.Value), outputAttribute,
                                                                    "BadlyCasedSpecialTaskAttribute", outputAttribute.Value, taskName, taskName);
                    this.taskParameterAttribute = outputAttribute;
                    break;

                case XMakeAttributes.itemName:
                    ProjectErrorUtilities.VerifyThrowInvalidProject(outputAttribute.Value.Length > 0, outputAttribute,
                                                                    "InvalidAttributeValue", outputAttribute.Value, outputAttribute.Name, XMakeElements.output);
                    this.itemNameAttribute = outputAttribute;
                    requiredData++;
                    break;

                case XMakeAttributes.propertyName:
                    ProjectErrorUtilities.VerifyThrowInvalidProject(outputAttribute.Value.Length > 0, outputAttribute,
                                                                    "InvalidAttributeValue", outputAttribute.Value, outputAttribute.Name, XMakeElements.output);
                    ProjectErrorUtilities.VerifyThrowInvalidProject(!ReservedPropertyNames.IsReservedProperty(outputAttribute.Value), node,
                                                                    "CannotModifyReservedProperty", outputAttribute.Value);
                    this.propertyNameAttribute = outputAttribute;
                    requiredData++;
                    break;

                case XMakeAttributes.condition:
                    this.conditionAttribute = outputAttribute;
                    break;

                default:
                    ProjectXmlUtilities.ThrowProjectInvalidAttribute(outputAttribute);
                    break;
                }
            }

            /* NOTE:
             *  TaskParameter must be specified
             *  either ItemName or PropertyName must be specified
             *  if ItemName is specified, then PropertyName cannot be specified
             *  if PropertyName is specified, then ItemName cannot be specified
             *  only Condition is truly optional
             */
            ProjectErrorUtilities.VerifyThrowInvalidProject((this.taskParameterAttribute != null) && (requiredData == 1),
                                                            node, "InvalidTaskOutputSpecification", taskName);
        }
示例#2
0
        /// <summary>
        /// Execute a PropertyGroup element, including each child property
        /// </summary>
        private void ExecutePropertyGroup(Lookup lookup)
        {
            foreach (BuildProperty property in backingPropertyGroup)
            {
                ArrayList buckets = null;

                try
                {
                    // Find all the metadata references in order to create buckets
                    List <string> parameterValues = new List <string>();
                    GetBatchableValuesFromProperty(parameterValues, property);
                    buckets = BatchingEngine.PrepareBatchingBuckets(taskNodeXmlElement, parameterValues, lookup);

                    // "Execute" each bucket
                    foreach (ItemBucket bucket in buckets)
                    {
                        if (Utilities.EvaluateCondition(property.Condition, property.ConditionAttribute,
                                                        bucket.Expander, null, ParserOptions.AllowAll, loggingServices, buildEventContext))
                        {
                            // Check for a reserved name now, so it fails right here instead of later when the property eventually reaches
                            // the outer scope.
                            ProjectErrorUtilities.VerifyThrowInvalidProject(!ReservedPropertyNames.IsReservedProperty(property.Name), property.PropertyElement,
                                                                            "CannotModifyReservedProperty", property.Name);

                            property.Evaluate(bucket.Expander);
                            bucket.Lookup.SetProperty(property);
                        }
                    }
                }
                finally
                {
                    if (buckets != null)
                    {
                        // Propagate the property changes to the bucket above
                        foreach (ItemBucket bucket in buckets)
                        {
                            bucket.Lookup.LeaveScope();
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Reads the settings for a specified tools version
        /// </summary>
        /// <param name="toolsVersion"></param>
        /// <param name="globalProperties"></param>
        /// <param name="initialProperties"></param>
        /// <param name="accumulateProperties"></param>
        /// <returns></returns>
        private Toolset ReadToolset(PropertyDefinition toolsVersion,
                                    BuildPropertyGroup globalProperties,
                                    BuildPropertyGroup initialProperties,
                                    bool accumulateProperties)
        {
            // Initial properties is the set of properties we're going to use to expand property expressions like $(foo)
            // in the values we read out of the registry or config file. We'll add to it as we pick up properties (including binpath)
            // from the registry or config file, so that properties there can be referenced in values below them.
            // After processing all the properties, we don't need initialProperties anymore.
            string             toolsPath  = null;
            string             binPath    = null;
            BuildPropertyGroup properties = new BuildPropertyGroup();

            IEnumerable <PropertyDefinition> rawProperties = GetPropertyDefinitions(toolsVersion.Name);
            Expander expander = new Expander(initialProperties);

            foreach (PropertyDefinition property in rawProperties)
            {
                if (String.Equals(property.Name, ReservedPropertyNames.toolsPath, StringComparison.OrdinalIgnoreCase))
                {
                    toolsPath = ExpandProperty(property, expander);
                    toolsPath = ExpandRelativePathsRelativeToExeLocation(toolsPath);

                    if (accumulateProperties)
                    {
                        SetProperty
                        (
                            new PropertyDefinition(ReservedPropertyNames.toolsPath, toolsPath, property.Source),
                            initialProperties,
                            globalProperties
                        );
                    }
                }
                else if (String.Equals(property.Name, ReservedPropertyNames.binPath, StringComparison.OrdinalIgnoreCase))
                {
                    binPath = ExpandProperty(property, expander);
                    binPath = ExpandRelativePathsRelativeToExeLocation(binPath);

                    if (accumulateProperties)
                    {
                        SetProperty
                        (
                            new PropertyDefinition(ReservedPropertyNames.binPath, binPath, property.Source),
                            initialProperties,
                            globalProperties
                        );
                    }
                }
                else if (ReservedPropertyNames.IsReservedProperty(property.Name))
                {
                    // We don't allow toolsets to define reserved properties
                    string baseMessage = ResourceUtilities.FormatResourceString("CannotModifyReservedProperty", property.Name);
                    InvalidToolsetDefinitionException.Throw("InvalidPropertyNameInToolset", property.Name, property.Source, baseMessage);
                }
                else
                {
                    // It's an arbitrary property
                    string             propertyValue    = ExpandProperty(property, expander);
                    PropertyDefinition expandedProperty = new PropertyDefinition(property.Name, propertyValue, property.Source);

                    SetProperty(expandedProperty, properties, globalProperties);

                    if (accumulateProperties)
                    {
                        SetProperty(expandedProperty, initialProperties, globalProperties);
                    }
                }

                if (accumulateProperties)
                {
                    expander = new Expander(initialProperties);
                }
            }

            // All tools versions must specify a value for MSBuildToolsPath (or MSBuildBinPath)
            if (String.IsNullOrEmpty(toolsPath) && String.IsNullOrEmpty(binPath))
            {
                InvalidToolsetDefinitionException.Throw("MSBuildToolsPathIsNotSpecified", toolsVersion.Name, toolsVersion.Source);
            }

            // If both MSBuildBinPath and MSBuildToolsPath are present, they must be the same
            if (toolsPath != null && binPath != null && !toolsPath.Equals(binPath, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            Toolset toolset = null;

            try
            {
                toolset = new Toolset(toolsVersion.Name, toolsPath ?? binPath, properties);
            }
            catch (ArgumentException e)
            {
                InvalidToolsetDefinitionException.Throw("ErrorCreatingToolset", toolsVersion.Name, e.Message);
            }

            return(toolset);
        }