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


C# TaskItem.CopyMetadata方法代码示例

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


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

示例1: Execute

        public override bool Execute()
        {
            try
            {
                List<ITaskItem> contentsList = new List<ITaskItem>();
                List<ITaskItem> dependencyList = new List<ITaskItem>();
                List<ITaskItem> templateList = new List<ITaskItem>();
                HashSet<Guid>   guids = new HashSet<Guid>();

                ProjectEx.Task = this;

                foreach (ITaskItem projectItem in projectFiles)
                {
                    string currentDirectory = Environment.CurrentDirectory;

                    ProjectEx project = new ProjectEx(projectItem);

                    project.Load();

                    Environment.CurrentDirectory = Path.GetDirectoryName(
                        project.FullFileName);

                    //Retrieve the list of Guids defined in the project, for later replacement.
                    string projectGuid = project.GetEvaluatedProperty("ProjectGuid");
                    if (!string.IsNullOrEmpty(projectGuid))
                    {
                        try
                        {
                            Guid guidProject = new Guid(projectGuid);
                            if (!guids.Contains(guidProject))
                            {
                                guids.Add(guidProject);
                            }
                        }
                        catch (FormatException)
                        {
                            Log.LogWarning("Project {0} has specified an ProjectGuid property not in the format of a Guid.", projectItem.ItemSpec);
                        }
                    }

                    string emulatorId = project.GetEvaluatedProperty("EmulatorId");
                    if (!string.IsNullOrEmpty(emulatorId))
                    {
                        try
                        {
                            Guid guidEmulator = new Guid(emulatorId);
                            if (!guids.Contains(guidEmulator))
                            {
                                guids.Add(guidEmulator);
                            }
                        }
                        catch (FormatException)
                        {
                            Log.LogWarning("Project {0} has specified an EmulatorId property not in the format of a Guid.", projectItem.ItemSpec);
                        }
                    }

                    //Select all the files referenced by the project.
                    foreach (string groupName in ProjectEx.FileGroups)
                    {
                        foreach (_BE.ProjectItem buildItem in project.MsBuildProject.GetItemsIgnoringCondition(groupName))
                        {
                            if (TransmorgificationUtilities.IsInRestrictedList(buildItem.Xml.Include))
                            {
                                Log.LogMessage("Skipping restricted file {0} in project {1}", buildItem.EvaluatedInclude, projectItem.ItemSpec);
                                continue;
                            }
                            else if (!File.Exists(buildItem.EvaluatedInclude)) // .GetMetadata("FullPath").EvaluatedValue))
                            {
                                Log.LogWarning("Cannot find file {0} referenced in project {1}", buildItem.EvaluatedInclude, projectItem.ItemSpec);
                                continue;
                            }

                            string fileName = buildItem.EvaluatedInclude;
                            if (Path.IsPathRooted(fileName))
                            {
                                Log.LogWarning("Project {0} references file {1} by absolute path, which is unsuitable for samples and templates", projectItem.ItemSpec, fileName);
                            }

                            TaskItem file = new TaskItem(fileName);
                            bool doReplacements = TransmorgificationUtilities.ValidMimeTypeForReplacements(buildItem.Xml.Include);
                            file.CopyMetadata(buildItem);
                            file.SetMetadata("DoReplacements", doReplacements.ToString().ToLowerInvariant());
                            file.SetMetadata("ItemCollection", buildItem.ItemType);
                            file.SetMetadata("ParentProject", projectItem.ItemSpec);
                            file.SetMetadata("ProjectDir", projectItem.GetMetadata("RelativeDir"));
                            string rootNamespace = project.GetEvaluatedProperty("RootNamespace");
                            if (rootNamespace == null)
                            {
                                rootNamespace = "";
                            }
                            file.SetMetadata("RootNamespace", rootNamespace);

                            contentsList.Add(file);
                        }
                    }

                    string templateIconFile = project.GetEvaluatedProperty("TemplateIconFile");
                    if (!string.IsNullOrEmpty(templateIconFile))
                    {
//.........这里部分代码省略.........
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:101,代码来源:GetProjectFiles.cs


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