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


C# PropertyDictionary.ImportProperties方法代码示例

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


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

示例1: InitializeProperties

        /// <summary>
        /// Initialize the properties which are used to evaluate the tasks files.
        /// </summary>
        private void InitializeProperties(ILoggingService loggingServices, BuildEventContext buildEventContext)
        {
            try
            {
                if (_propertyBag == null)
                {
                    List<ProjectPropertyInstance> reservedProperties = new List<ProjectPropertyInstance>();

                    reservedProperties.Add(ProjectPropertyInstance.Create(ReservedPropertyNames.binPath, EscapingUtilities.Escape(ToolsPath), mayBeReserved: true));
                    reservedProperties.Add(ProjectPropertyInstance.Create(ReservedPropertyNames.toolsVersion, ToolsVersion, mayBeReserved: true));

                    reservedProperties.Add(ProjectPropertyInstance.Create(ReservedPropertyNames.toolsPath, EscapingUtilities.Escape(ToolsPath), mayBeReserved: true));
                    reservedProperties.Add(ProjectPropertyInstance.Create(ReservedPropertyNames.assemblyVersion, Constants.AssemblyVersion, mayBeReserved: true));

                    // Add one for the subtoolset version property -- it may or may not be set depending on whether it has already been set by the 
                    // environment or global properties, but it's better to create a dictionary that's one too big than one that's one too small.  
                    int count = _environmentProperties.Count + reservedProperties.Count + Properties.Values.Count + _globalProperties.Count + 1;

                    // GenerateSubToolsetVersion checks the environment and global properties, so it's safe to go ahead and gather the 
                    // subtoolset properties here without fearing that we'll have somehow come up with the wrong subtoolset version. 
                    string subToolsetVersion = this.GenerateSubToolsetVersion();
                    SubToolset subToolset;
                    ICollection<ProjectPropertyInstance> subToolsetProperties = null;

                    if (subToolsetVersion != null)
                    {
                        if (SubToolsets.TryGetValue(subToolsetVersion, out subToolset))
                        {
                            subToolsetProperties = subToolset.Properties.Values;
                            count += subToolsetProperties.Count;
                        }
                    }

                    _propertyBag = new PropertyDictionary<ProjectPropertyInstance>(count);

                    // Should be imported in the same order as in the evaluator:  
                    // - Environment
                    // - Toolset
                    // - Subtoolset (if any) 
                    // - Global
                    _propertyBag.ImportProperties(_environmentProperties);

                    _propertyBag.ImportProperties(reservedProperties);

                    _propertyBag.ImportProperties(Properties.Values);

                    if (subToolsetVersion != null)
                    {
                        _propertyBag.Set(ProjectPropertyInstance.Create(Constants.SubToolsetVersionPropertyName, subToolsetVersion));
                    }

                    if (subToolsetProperties != null)
                    {
                        _propertyBag.ImportProperties(subToolsetProperties);
                    }

                    _propertyBag.ImportProperties(_globalProperties);
                }

                if (_expander == null)
                {
                    _expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(_propertyBag);
                }
            }
            catch (Exception e)
            {
                if (ExceptionHandling.NotExpectedException(e))
                {
                    // Catching Exception, but rethrowing unless it's an IO related exception.
                    throw;
                }

                loggingServices.LogError(buildEventContext, new BuildEventFileInfo(/* this warning truly does not involve any file it is just gathering properties */String.Empty), "TasksPropertyBagError", e.Message);
            }
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:78,代码来源:Toolset.cs

示例2: ToolsetConfigurationReader

        /// <summary>
        /// Gathers toolset data from the registry and configuration file, if any.
        /// NOTE:  this method is internal for unit testing purposes only.
        /// </summary>
        internal static string ReadAllToolsets
            (
            Dictionary<string, Toolset> toolsets,
            ToolsetRegistryReader registryReader,
            ToolsetConfigurationReader configurationReader,
            PropertyDictionary<ProjectPropertyInstance> environmentProperties,
            PropertyDictionary<ProjectPropertyInstance> globalProperties,
            ToolsetDefinitionLocations locations
            )
        {
            PropertyDictionary<ProjectPropertyInstance> initialProperties = new PropertyDictionary<ProjectPropertyInstance>(environmentProperties);

            initialProperties.ImportProperties(globalProperties);

            // The ordering here is important because the configuration file should have greater precedence
            // than the registry, and we do a check and don't read in the new toolset if there's already one. 
            string defaultToolsVersionFromConfiguration = null;
            string overrideTasksPathFromConfiguration = null;
            string defaultOverrideToolsVersionFromConfiguration = null;

            if ((locations & ToolsetDefinitionLocations.ConfigurationFile) == ToolsetDefinitionLocations.ConfigurationFile)
            {
                if (configurationReader == null && ToolsetConfigurationReaderHelpers.ConfigurationFileMayHaveToolsets())
                {
                    // We haven't been passed in a fake configuration reader by a unit test,
                    // and it looks like we have a .config file to read, so create a real
                    // configuration reader
                    configurationReader = new ToolsetConfigurationReader(environmentProperties, globalProperties);
                }

                if (configurationReader != null)
                {
                    // Accumulation of properties is okay in the config file because it's deterministically ordered
                    defaultToolsVersionFromConfiguration = configurationReader.ReadToolsets(toolsets, globalProperties,
                        initialProperties, true /* accumulate properties */, out overrideTasksPathFromConfiguration,
                        out defaultOverrideToolsVersionFromConfiguration);
                }
            }

            string defaultToolsVersionFromRegistry = null;
            string overrideTasksPathFromRegistry = null;
            string defaultOverrideToolsVersionFromRegistry = null;

            if ((locations & ToolsetDefinitionLocations.Registry) == ToolsetDefinitionLocations.Registry)
            {
                // If we haven't been provided a registry reader (i.e. unit tests), create one
                registryReader = registryReader ?? new ToolsetRegistryReader(environmentProperties, globalProperties);

                // We do not accumulate properties when reading them from the registry, because the order
                // in which values are returned to us is essentially random: so we disallow one property
                // in the registry to refer to another also in the registry
                defaultToolsVersionFromRegistry = registryReader.ReadToolsets(toolsets, globalProperties,
                    initialProperties, false /* do not accumulate properties */, out overrideTasksPathFromRegistry,
                    out defaultOverrideToolsVersionFromRegistry);
            }

            // The 2.0 .NET Framework installer did not write a ToolsVersion key for itself in the registry. 
            // The 3.5 installer writes one for 2.0, but 3.5 might not be installed.  
            // The 4.0 and subsequent installers can't keep writing the 2.0 one, because (a) it causes SxS issues and (b) we 
            // don't want it unless 2.0 is installed.
            // So if the 2.0 framework is actually installed, we're reading the registry, and either the registry or the config
            // file have not already created the 2.0 toolset, mock up a fake one.  
            if (
                ((locations & ToolsetDefinitionLocations.Registry) != 0) &&
                !toolsets.ContainsKey("2.0") &&
                FrameworkLocationHelper.PathToDotNetFrameworkV20 != null
              )
            {
                Toolset synthetic20Toolset = new Toolset("2.0", FrameworkLocationHelper.PathToDotNetFrameworkV20, environmentProperties, globalProperties, null /* 2.0 did not have override tasks */, null /* 2.0 did not have a default override toolsversion */);
                toolsets.Add("2.0", synthetic20Toolset);
            }

            // We'll use the path from the configuration file if it was specified, otherwise we'll try
            // the one from the registry.  It's possible (and valid) that neither the configuration file
            // nor the registry specify a override in which case we'll just return null.
            string overrideTasksPath = overrideTasksPathFromConfiguration ?? overrideTasksPathFromRegistry;

            // We'll use the path from the configuration file if it was specified, otherwise we'll try
            // the one from the registry.  It's possible (and valid) that neither the configuration file
            // nor the registry specify a override in which case we'll just return null.
            string defaultOverrideToolsVersion = defaultOverrideToolsVersionFromConfiguration ?? defaultOverrideToolsVersionFromRegistry;

            // We'll use the default from the configuration file if it was specified, otherwise we'll try
            // the one from the registry.  It's possible (and valid) that neither the configuration file
            // nor the registry specify a default, in which case we'll just return null.
            string defaultToolsVersion = defaultToolsVersionFromConfiguration ?? defaultToolsVersionFromRegistry;

            // If we got a default version from the registry or config file, and it
            // actually exists, fine.
            // Otherwise we have to come up with one.
            if (defaultToolsVersion == null || !toolsets.ContainsKey(defaultToolsVersion))
            {
                // We're going to choose a hard coded default tools version of 2.0.
                defaultToolsVersion = Constants.defaultToolsVersion;

                // But don't overwrite any existing tools path for this default we're choosing.
//.........这里部分代码省略.........
开发者ID:cdmihai,项目名称:msbuild,代码行数:101,代码来源:ToolsetReader.cs


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