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


C# ProjectItems.AddFromFile方法代码示例

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


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

示例1: AddItem

 public static void AddItem(string ttInclude, string vsVersion, string netVersion, string ttIncludeName, string templatesFolder, HashSet<string> existingTTIncludes, ProjectItems templatesProjectItems)
 {
     var m = Regex.Match(ttInclude, @".(NET\d+).");
     if (!m.Success || m.Groups[1].Value == netVersion)
     {
         const string x64Key = @"Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows";
         if (ttIncludeName.EndsWith(".x64"))
         {
             try
             {
                 if (Registry.LocalMachine.OpenSubKey(x64Key) == null)
                 {
                     return;
                 }
                 ttIncludeName = ttIncludeName.Substring(0, ttIncludeName.Length - 4);
             }
             catch
             {
                 return;
             }
         }
         else if (ttIncludeName.EndsWith(".x86"))
         {
             try
             {
                 if (Registry.LocalMachine.OpenSubKey(x64Key) != null)
                 {
                     return;
                 }
             }
             catch
             {
             }
             ttIncludeName = ttIncludeName.Substring(0, ttIncludeName.Length - 4);
         }
         var ttIncludeCopy = Path.Combine(templatesFolder, ttIncludeName);
         if (!existingTTIncludes.Contains(ttIncludeName))
         {
             templatesProjectItems.AddFromFile(ttIncludeCopy);
         }
         if (ttIncludeName.Contains("." + vsVersion + "." + netVersion + "."))
         {
             ttIncludeCopy = ttIncludeCopy.Substring(0, ttIncludeCopy.Length - 10) + ".merge.tt";
             ttIncludeName = Path.GetFileName(ttIncludeCopy);
             if (!existingTTIncludes.Contains(ttIncludeName))
             {
                 templatesProjectItems.AddFromFile(ttIncludeCopy);
             }
         }
     }
 }
开发者ID:bnjMichel,项目名称:waqs,代码行数:51,代码来源:TemplatesCopying.cs

示例2: CopyProjectItems

 private static void CopyProjectItems(ProjectItems sourceItems, ProjectItems targetItems)
 {
     foreach (ProjectItem projectItem in sourceItems)
     {
         ProjectItem tempItem = null;
         try
         {
             tempItem = targetItems.Item(projectItem.Name);
         }
         catch (ArgumentException)
         {
             if (projectItem.Kind == "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}")
             {
                 if (projectItem.Name != "Properties")
                 {
                     tempItem = targetItems.AddFolder(projectItem.Name);
                 }
             }
             else if (projectItem.Name != "packages.config")
             {
                 tempItem = targetItems.AddFromFile(projectItem.Properties.Item("LocalPath").Value as string);
             }
         }
         if (tempItem != null)
         {
             CopyProjectItems(projectItem.ProjectItems, tempItem.ProjectItems);
         }
     }
 }
开发者ID:cgoconseils,项目名称:XrmFramework,代码行数:29,代码来源:ProjectHelper.cs

示例3: AddFileToProject

    private ProjectItem AddFileToProject (ProjectItems projectItems, string licenseHeaderDefinitionFileName)
    {
      int fileCountBefore = projectItems.Count;
      var newProjectItem = projectItems.AddFromFile (licenseHeaderDefinitionFileName);

      int fileCountAfter = projectItems.Count;
      if (fileCountBefore == fileCountAfter)
      {
        MessageBox.Show (Resources.Warning_CantLinkItemInSameProject, Resources.NameOfThisExtension, MessageBoxButton.OK,
          MessageBoxImage.Information);
      }

      return newProjectItem;
    }
开发者ID:Vault16Software,项目名称:LicenseHeaderManager,代码行数:14,代码来源:AddExistingLicenseHeaderDefinitionFileCommand.cs

示例4: CopyTemplates

        public static void CopyTemplates(DTE dte, string templatesFolderName, string netVersion, string toolsPath, string vsVersion, out string templatesFolder, out HashSet<string> existingTTIncludes, out ProjectItems templatesProjectItems)
        {
            var slnFolder = Path.GetDirectoryName(dte.Solution.FullName);
            templatesFolder = Path.Combine(slnFolder, templatesFolderName);
            if (!Directory.Exists(templatesFolder))
            {
                Directory.CreateDirectory(templatesFolder);
            }

            const string solutionItemsFolderName = "Solution Items";
            Project solutionItems = dte.Solution.Projects.OfType<Project>().FirstOrDefault(pi => pi.Name == solutionItemsFolderName);
            UIHierarchyItem solutionItemsUIHierarchyItem = null;
            Action setSolutionItemsUIHierarchyItem = () => solutionItemsUIHierarchyItem = (dte.Windows.Cast<Window>().First(w => w.Type == vsWindowType.vsWindowTypeSolutionExplorer).Object as UIHierarchy)?.UIHierarchyItems.Cast<UIHierarchyItem>().First().UIHierarchyItems.Cast<UIHierarchyItem>().First(uihi => uihi.Name == solutionItemsFolderName);
            bool solutionItemsExpanded;

            Project templates = null;
            UIHierarchyItem templatesUIHierarchyItem = null;
            Action setTemplatesUIHierarchyItem = () => templatesUIHierarchyItem = solutionItemsUIHierarchyItem.UIHierarchyItems.Cast<UIHierarchyItem>().First(uihi => uihi.Name == templatesFolderName);
            bool templatesItemsExpanded = false;
            Action addTemplatesUIHierarchyItem = () =>
            {
                templates = ((EnvDTE80.SolutionFolder)solutionItems.Object).AddSolutionFolder(templatesFolderName);
                setTemplatesUIHierarchyItem();
                templatesItemsExpanded = false;
            };

            if (solutionItems == null)
            {
                solutionItems = ((EnvDTE80.Solution2)dte.Solution).AddSolutionFolder(solutionItemsFolderName);
                setSolutionItemsUIHierarchyItem();
                solutionItemsExpanded = false;
                addTemplatesUIHierarchyItem();
            }
            else
            {
                setSolutionItemsUIHierarchyItem();
                solutionItemsExpanded = solutionItemsUIHierarchyItem.UIHierarchyItems.Expanded;

                templates = ((IEnumerable)solutionItems.ProjectItems).Cast<ProjectItem>().FirstOrDefault(pi => pi.Name == templatesFolderName).SubProject;
                if (templates == null)
                {
                    addTemplatesUIHierarchyItem();
                }
                else
                {
                    setTemplatesUIHierarchyItem();
                    templatesItemsExpanded = templatesUIHierarchyItem.UIHierarchyItems.Expanded;
                }
            }

            var ttincludesFolder = Path.Combine(toolsPath, "ttincludes");
            templatesProjectItems = (ProjectItems)templates.ProjectItems;
            existingTTIncludes = new HashSet<string>(templatesProjectItems.Cast<ProjectItem>().Select(pi => pi.Name));
            string ttIncludeName = null;
            foreach (var ttInclude in Directory.GetFiles(ttincludesFolder).Where(f => (ttIncludeName = Path.GetFileName(f)).StartsWith("WAQS.")))
            {
                AddItem(ttInclude, vsVersion, netVersion, ttIncludeName, templatesFolder, existingTTIncludes, templatesProjectItems);
            }
            var ttIncludesFolderVS = Path.Combine(ttincludesFolder, vsVersion);
            foreach (var ttInclude in Directory.GetFiles(ttIncludesFolderVS).Where(f => (ttIncludeName = Path.GetFileName(f)).StartsWith("WAQS.")))
            {
                AddItem(ttInclude, vsVersion, netVersion, ttIncludeName, templatesFolder, existingTTIncludes, templatesProjectItems);
            }
            const string mergeTTIncludeFileName = "MergeT4Files.ttinclude";
            File.Copy(Path.Combine(ttincludesFolder, mergeTTIncludeFileName), Path.Combine(templatesFolder, mergeTTIncludeFileName), true);
            var specialMergeFolder = Path.Combine(ttincludesFolder, "SpecialMerge");
            foreach (var specialMerge in Directory.GetFiles(specialMergeFolder))
            {
                var ttSpecialMergeFileName = Path.GetFileName(specialMerge);
                var specialMergeFile = Path.Combine(specialMergeFolder, ttSpecialMergeFileName);
                var ttSpecialMergeFileCopy = Path.Combine(templatesFolder, ttSpecialMergeFileName);
                File.Copy(specialMergeFile, ttSpecialMergeFileCopy, true);
                if (!existingTTIncludes.Contains(ttSpecialMergeFileName))
                {
                    templatesProjectItems.AddFromFile(ttSpecialMergeFileCopy);
                }
            }
            try
            {
                templatesUIHierarchyItem.UIHierarchyItems.Expanded = templatesItemsExpanded;
                solutionItemsUIHierarchyItem.UIHierarchyItems.Expanded = solutionItemsExpanded;
            }
            catch
            {
            }
            MergeTTIncludes(dte, templates, templatesFolder);
        }
开发者ID:bnjMichel,项目名称:waqs,代码行数:87,代码来源:TemplatesCopying.cs

示例5: 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

示例6: AddFileToContainer

 protected override void AddFileToContainer(string fullPath, ProjectItems container)
 {
     container.AddFromFile(fullPath);
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:4,代码来源:JsProjectSystem.cs

示例7: AddFromFile

 internal ProjectItem AddFromFile(ProjectItems projectItems, string filename)
 {
   return projectItems.AddFromFile(filename);
 }
开发者ID:manuel11g,项目名称:SharePoint-Software-Factory,代码行数:4,代码来源:WSPExtractor.cs

示例8: ProcessDownloadedSolution

        private bool ProcessDownloadedSolution(DirectoryInfo extractedFolder, string baseFolder, ProjectItems projectItems)
        {
            bool itemChanged = false;

            //Handle file adds
            foreach (FileInfo file in extractedFolder.GetFiles())
            {
                if (File.Exists(baseFolder + "\\" + file.Name))
                {
                    if (FileEquals(baseFolder + "\\" + file.Name, file.FullName))
                        continue;
                }

                File.Copy(file.FullName, baseFolder + "\\" + file.Name, true);
                projectItems.AddFromFile(baseFolder + "\\" + file.Name);
                itemChanged = true;
            }

            //Handle folder adds
            foreach (DirectoryInfo folder in extractedFolder.GetDirectories())
            {
                if (!Directory.Exists(baseFolder + "\\" + folder.Name))
                    Directory.CreateDirectory(baseFolder + "\\" + folder.Name);

                var newProjectItems = projectItems;
                bool subItemChanged = ProcessDownloadedSolution(folder, baseFolder + "\\" + folder.Name, newProjectItems);
                if (subItemChanged)
                    itemChanged = true;
            }

            return itemChanged;
        }
开发者ID:ikurtev,项目名称:CRMDeveloperExtensions,代码行数:32,代码来源:SolutionList.xaml.cs

示例9: ProcessCssFile

        private static void ProcessCssFile(ProjectItems parent, string cssPath)
        {
            var sassPath = $"{Path.Combine(Path.GetDirectoryName(cssPath), Path.GetFileNameWithoutExtension(cssPath))}.scss";
            var sassProjectItem = AssetCache.Lookup(sassPath);

            try
            {
                if (sassProjectItem != null)
                    parent = sassProjectItem.ProjectItems;

                parent.AddFromFile(cssPath);
            }
            catch (Exception e)
            {
                Logger.WriteLine("Exception encountered when trying to add a file to the project");
                Logger.WriteLine(e.Message);
                Logger.WriteLine("Stack trace:");
                Logger.WriteLine(e.StackTrace);
            }
        }
开发者ID:Orchidsoft,项目名称:vs-net-dte,代码行数:20,代码来源:MainPackage.cs

示例10: AddFromFileWithFolders

		private void AddFromFileWithFolders(ProjectItems root, string name, string dir)
		{
			string pathToNow = null;
			var tmp = name.Split('\\');
			for (int i = 0; i < tmp.Length - 1; i++)
			{
				string thisDir = tmp[i];
				pathToNow = pathToNow == null ? thisDir : Path.Combine(pathToNow, thisDir);

				var item = Find(root, thisDir);
				if (item == null)
				{
					//AddExistingFolder(root.ContainingProject, pathToNow);

					//item = Find(root, thisDir);
					//if (item == null)
					item = root.AddFolder(thisDir);
				}

				root = item.ProjectItems;
			}

			if (Find(root, tmp[tmp.Length - 1]) == null)
				root.AddFromFile(Path.Combine(dir, name));
		}
开发者ID:pescuma,项目名称:modelsharp,代码行数:25,代码来源:ModelSharpTool.cs

示例11: duplicateFiles

 private void duplicateFiles(ProjectItems projItems)
 {
     ProjectItem projItem;
     for (int i = 1; i <= projItems.Count; i++)
     {
         projItem = projItems.Item(i);
         Debug.Write(projItem.Name + "  " + projItem.Kind);
         try
         {
             if (projItem.ProjectItems.Count > 0)
             {
                 duplicateFiles(projItem.ProjectItems);
             }
             else if (selectedProjectItems.Contains(projItem))
             {
                 selectedProjectItems.Remove(projItem);
                 String newPath = copyFile(projItem);
                 if (newPath != null)
                 {
                     try
                     {
                         lastAdded = projItems.AddFromFile(newPath);
                     }
                     catch (Exception) { }
                 }
             }
         }
         catch (Exception)
         {
         }
     }
 }
开发者ID:Spraylight,项目名称:MurlTools,代码行数:32,代码来源:MurlToolsPackage.cs

示例12: CreateTestProjectItemFromFile

        protected static ProjectItem CreateTestProjectItemFromFile(ProjectItems projectItems, string fileName)
        {
            if (projectItems == null)
            {
                throw new ArgumentNullException("projectItems");
            }

            if (!File.Exists(fileName))
            {
                File.WriteAllText(fileName, string.Empty);                
            }

            return projectItems.AddFromFile(fileName);
        }
开发者ID:icool123,项目名称:T4Toolbox,代码行数:14,代码来源:IntegrationTest.cs

示例13: AddFileToProject

		private static void AddFileToProject(ProjectItems items, string filePath, string subDirectories, string fileText)
		{
			//ProjectItem destination = items.Item(0);
			string[] directories = subDirectories.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
			int depth = directories.Length;
			for (int i = 0; i < depth && items != null; ++i)
			{
				// This assumes the directory is there. If it is not, then
				// the guidelines for creating test libraries were not followed
				string directoryName = directories[i];
				ProjectItems nextItems = null;
				foreach (ProjectItem testItem in items)
				{
					if (testItem.Name == directoryName)
					{
						nextItems = testItem.ProjectItems;
						break;
					}
				}
				items = nextItems;
			}
			if (items != null)
			{
				File.WriteAllText(filePath, fileText, Encoding.UTF8);
				ProjectItem newItem = items.AddFromFile(filePath);
				SetFileProperties(newItem);
			}
		}
开发者ID:cjheath,项目名称:NORMA,代码行数:28,代码来源:ReportViewer.cs

示例14: AddFromFile

        internal static ProjectItem AddFromFile(ProjectItems projectItems, string filename)
        {
            ProjectItem pitem = projectItems.AddFromFile(filename);

            try
            {
                Helpers.CheckSharePointReferences(pitem);
                //Helpers.LogMessage(projectItems.DTE, projectItems.DTE, filename + ": File Added");
           }
            catch (Exception)
            {
            }

            return pitem;
        }
开发者ID:manuel11g,项目名称:SharePoint-Software-Factory,代码行数:15,代码来源:Helpers.cs

示例15: ProcessCssFile

        private static void ProcessCssFile(ProjectItems parent, string cssPath)
        {
            var sassPath = $"{Path.Combine(Path.GetDirectoryName(cssPath), Path.GetFileNameWithoutExtension(cssPath))}.scss";
            var sassProjectItem = AssetCache.Lookup(sassPath);

            if (sassProjectItem != null)
                parent = sassProjectItem.ProjectItems;

            parent.AddFromFile(cssPath);
        }
开发者ID:matt40k,项目名称:vs-net-dte,代码行数:10,代码来源:MainPackage.cs


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