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


C# ProjectItems.AddFromFileCopy方法代码示例

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


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

示例1: AddFilesAndFolders

        /// <summary>
        /// Adds the files and folders.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="targetProjectType">Type of the target project.</param>
        /// <param name="levels">The number of levels to walk down the chain. If <c>-1</c>, it will handle all levels.</param>
        /// <param name="fileFilter">An enumerable of files that should be handled with care, can be <c>null</c>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="source" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="target" /> is <c>null</c>.</exception>
        private void AddFilesAndFolders(ProjectItems source, ProjectItems target, ProjectType targetProjectType, int levels, IEnumerable<string> fileFilter)
        {
            Argument.IsNotNull("source", source);
            Argument.IsNotNull("target", target);

            string targetParentName = target.Parent.GetObjectName();

            Log.Debug("Adding files and folders to target '{0}'", targetParentName);

            if (levels == 0)
            {
                return;
            }

            levels--;

            foreach (ProjectItem sourceItem in source)
            {
                var sourceItemName = sourceItem.Name;

                if (sourceItem.IsLinkedFile())
                {
                    Log.Debug("Skipping item '{0}' because it is a linked file (so has another root project)", sourceItem.GetObjectName());

                    continue;
                }

                if (ShouldSkipAddingOfItem(sourceItem, targetProjectType))
                {
                    Log.Debug("Skipping item '{0}' because it is ignored by a rule for target project {1}", sourceItem.GetObjectName(), targetProjectType);

                    continue;
                }

                ProjectItem existingTargetItem = null;
                foreach (ProjectItem targetItem in target)
                {
                    if (string.Equals(targetItem.Name, sourceItemName))
                    {
                        existingTargetItem = targetItem;
                        break;
                    }
                }

                bool isFolder = sourceItem.IsFolder();
                bool containsSubItems = isFolder || sourceItem.ContainsChildItems();

                if (existingTargetItem == null)
                {
                    if (!isFolder)
                    {
                        if (sourceItem.IsXamlFile() && ((targetProjectType == ProjectType.NET40) || (targetProjectType == ProjectType.NET45)))
                        {
                            Log.Debug("File '{0}' is a xaml file and the target project is NET40 or NET45. There is a bug in Visual Studio that does not allow to link xaml files in NET40, so a copy is created.", sourceItem.FileNames[0]);

                            // string targetFile = sourceItem.GetTargetFileName(target);
                            // File.Copy(sourceItem.FileNames[0], targetFile);
                            existingTargetItem = target.AddFromFileCopy(sourceItem.FileNames[0]);
                        }
                        else
                        {
                            Log.Debug("Adding link to file '{0}'", sourceItem.FileNames[0]);

                            try
                            {
                                // Linked file
                                existingTargetItem = target.AddFromFile(sourceItem.FileNames[0]);
                            }
                            catch (Exception ex)
                            {
                                var messageService = ServiceLocator.Default.ResolveType<IMessageService>();
                                messageService.ShowError(ex);
                            }
                        }
                    }
                    else
                    {
                        Log.Debug("Adding folder '{0}'", sourceItem.FileNames[0]);

                        string targetDirectory = sourceItem.GetTargetFileName(target.ContainingProject);
                        existingTargetItem = Directory.Exists(targetDirectory) ? target.AddFromDirectory(targetDirectory) : target.AddFolder(sourceItem.Name);
                    }

                    if (existingTargetItem != null)
                    {
                        Log.Debug("Added item '{0}'", existingTargetItem.Name);
                    }
                }

                bool isResourceFile = sourceItem.IsResourceFile();
//.........这里部分代码省略.........
开发者ID:GeertvanHorrik,项目名称:Caitlyn,代码行数:101,代码来源:Linker.cs

示例2: AddItem

 /// <summary>
 /// Adds the item.
 /// </summary>
 /// <param name="project">The project.</param>
 /// <param name="projectItems">The project items.</param>
 private void AddItem(Project project, ProjectItems projectItems)
 {
     if(!overwriteItemIfExists)
     {
         outputProjectItem = DteHelper.FindItemByName(projectItems, Path.GetFileName(sourceFilePath), false);
         if (outputProjectItem == null)
         {
             outputProjectItem = projectItems.AddFromFileCopy(sourceFilePath);
         }
     }
     else
     {
         File.Copy(sourceFilePath,
             Path.Combine(projectItem.Properties.Item("FullPath").Value.ToString(),
                          Path.GetFileName(sourceFilePath)),
             true);
     }
 }
开发者ID:riseandcode,项目名称:open-wscf-2010,代码行数:23,代码来源:AddProjectItemFromFileAction.cs

示例3: CreateDocumentFromCopy

        /// <summary>
        /// 将一个已经存在的文件加入项目
        /// </summary>
        /// <param name="projectItems">某个项目下面的ProjectItems</param>
        /// <param name="path">要加入的文件的路径</param>
        public void CreateDocumentFromCopy(ProjectItems projectItems, string path)
        {
            if (VSSolution.CurrentSolution2 != null)
            {
                if (!File.Exists(path))
                {
                    throw new NullReferenceException("要加载的文件不存在");
                }
                string givingName = path.Substring(path.LastIndexOf('\\') + 1, path.LastIndexOf('.') - path.LastIndexOf('\\') - 1);

                //检测是否已经存在该文件

                List<ProjectItem> allFileProjectItem = GetAllFileProjectItem(projectItems);
                ProjectItem projectItem = allFileProjectItem.Find(i => i.Name == givingName);
                if (projectItem != null)
                {
                    MessageBox.Show("已经存在给定的文件");
                }
                else
                {
                    try
                    {
                        projectItems.AddFromFileCopy(path);
                    }
                    catch (COMException e)
                    {
                        MessageBox.Show(e.Message);
                    }
                }
            }
        }
开发者ID:qianlifeng,项目名称:easyvsx,代码行数:36,代码来源:VSProject.cs

示例4: AddFromItemFilePath

 private static void AddFromItemFilePath(Project project, ProjectItems items, NewItemDynamicParameters p)
 {
     items.AddFromFileCopy(p.ItemFilePath);
 }
开发者ID:wangchunlei,项目名称:MyGit,代码行数:4,代码来源:NewProjectItemManager.cs


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