/// <summary> /// </summary> protected virtual void AddCMake() { var cMakeLists = Path.Combine(UserPrefs.SolutionDirectory, @"CMakeLists.txt"); ProjectSources.CopyFile(ProjectSources.CMakeLists, cMakeLists); ProjectSources.CopyDirectory(ProjectSources.CMake, Path.Combine(UserPrefs.SolutionDirectory, @"cmake")); ReplaceParameters(cMakeLists); Project.AddFile(cMakeLists); }
// ------------------------------------------------------ /// <summary> /// Creates the test runner source file for the current startup /// project and adds it to the project. /// </summary> /// <param name="doNotRunTests"> /// If true, the file will be generated but will not include any /// statements to run any tests. If false, the tests will be run /// based on the current selection in the CxxTest Suites view. /// </param> public void CreateTestRunnerFile(bool doNotRunTests) { TestSuiteCollection suites = AllTestSuites; Dictionary <string, bool> testsToRun; if (doNotRunTests) { testsToRun = null; } else { testsToRun = TryToGetTestsToRun(); } HierarchyItem startupProject = VsShellUtils.GetStartupProject(this); string projectDir = startupProject.ProjectDirectory; string workingDir = GetActiveWorkingDirectory(startupProject); Project project = startupProject.GetExtObjectAs <Project>(); string runnerPath = Path.Combine( projectDir, Constants.TestRunnerFilename); // Remove the file from the project if necessary, and delete it // from the file system if it exists. VCProject vcproj = (VCProject)project.Object; if (!vcproj.CanAddFile(runnerPath)) { IVCCollection coll = (IVCCollection)vcproj.Files; vcproj.RemoveFile(coll.Item(Constants.TestRunnerFilename)); } if (File.Exists(runnerPath)) { File.Delete(runnerPath); } TestRunnerGenerator generator = new TestRunnerGenerator(runnerPath, suites, testsToRun); generator.Generate(); // Add the file to the project. vcproj.AddFile(runnerPath); }
public void AddToFilter(EnvDTE.Project dteProject, String name, String path) { VCProject project = dteProject.Object as VCProject; VCFilter filter = null; foreach (VCFilter f in project.Filters) { if (f.Name.Equals(name)) { filter = f; break; } } if (filter != null) { filter.AddFile(path); } else { project.AddFile(path); } }
public static void SyncIncludeFiles(VCProject vcproj, List<string> priFiles, List<string> projFiles, EnvDTE.DTE dte, bool flat, FakeFilter fakeFilter) { List<string> cmpPriFiles = new List<string>(priFiles.Count); foreach (string s in priFiles) cmpPriFiles.Add(HelperFunctions.NormalizeFilePath(s).ToLower()); cmpPriFiles.Sort(); List<string> cmpProjFiles = new List<string>(projFiles.Count); foreach (string s in projFiles) cmpProjFiles.Add(HelperFunctions.NormalizeFilePath(s).ToLower()); QtProject qtPro = QtProject.Create(vcproj); Hashtable filterPathTable = new Hashtable(17); Hashtable pathFilterTable = new Hashtable(17); if (!flat && fakeFilter != null) { VCFilter rootFilter = qtPro.FindFilterFromGuid(fakeFilter.UniqueIdentifier); if (rootFilter == null) qtPro.AddFilterToProject(Filters.SourceFiles()); CollectFilters(rootFilter, null, ref filterPathTable, ref pathFilterTable); } // first check for new files foreach(string file in cmpPriFiles) { if (cmpProjFiles.IndexOf(file) > -1) continue; if (flat) { vcproj.AddFile(file); // the file is not in the project } else { string path = HelperFunctions.GetRelativePath(vcproj.ProjectDirectory, file); if (path.StartsWith(".\\")) path = path.Substring(2); int i = path.LastIndexOf('\\'); if (i > -1) path = path.Substring(0, i); else path = "."; if (pathFilterTable.Contains(path)) { VCFilter f = pathFilterTable[path] as VCFilter; f.AddFile(file); continue; } VCFilter filter = BestMatch(path, pathFilterTable); string filterDir = filterPathTable[filter] as string; string name = path; if (!name.StartsWith("..") && name.StartsWith(filterDir)) name = name.Substring(filterDir.Length + 1); VCFilter newFilter = filter.AddFilter(name) as VCFilter; newFilter.AddFile(file); filterPathTable.Add(newFilter, path); pathFilterTable.Add(path, newFilter); } } // then check for deleted files foreach (string file in cmpProjFiles) { if (cmpPriFiles.IndexOf(file) == -1) { // the file is not in the pri file // (only removes it from the project, does not del. the file) FileInfo info = new FileInfo(file); HelperFunctions.RemoveFileInProject(vcproj, file); Messages.PaneMessage(dte, "--- (Importing .pri file) file: " + info.Name + " does not exist in .pri file, move to " + vcproj.ProjectDirectory + "Deleted"); } } }
static void Main(string[] args) { try { // Create a project engine VCProjectEngine projEngine = new VCProjectEngineObject(); // Load a project, change the name, add a configuration VCProject project = (VCProject)projEngine.LoadProject(@"..\..\..\MyProject\MyProject.vcproj"); if (project != null) { //Change the project's name project.Name = "Voila"; //Add a new configuration project.AddConfiguration("Whichever Name"); // Get the debug configuration and change the type to application VCConfiguration configuration = (VCConfiguration)(((IVCCollection)project.Configurations).Item("Debug")); if (configuration != null) { configuration.ConfigurationType = ConfigurationTypes.typeApplication; } else { Console.WriteLine(@"I Couldn't find the configuration"); } // Get the linker tool from the configration. VCLinkerTool linkerTool = (VCLinkerTool)(((IVCCollection)configuration.Tools).Item("VCLinkerTool")); if (linkerTool != null) { // Change the ShowProgress property to "Display All Progress Messages (/VERBOSE)" linkerTool.ShowProgress = linkProgressOption.linkProgressAll; } else { Console.WriteLine(@"I Couldn't find the linkerTool"); } // Add a cpp file called New.cpp if (project.CanAddFile("New.cpp")) { project.AddFile("New.cpp"); } else { Console.WriteLine(@"I Couldn't add the file"); } // Access the files collection IVCCollection filesCollection = (IVCCollection)project.Files; if (filesCollection != null) { // Access a cpp files called bar.cpp that is already in the project. VCFile file = (VCFile)(filesCollection.Item("Existing.cpp")); if (file != null) { // Access the release configuration of this file. VCFileConfiguration fileConfiguration = (VCFileConfiguration)(((IVCCollection)file.FileConfigurations).Item("Release|Win32")); // Get the compiler tool associated with this file. VCCLCompilerTool compilerTool = (VCCLCompilerTool)fileConfiguration.Tool; // Change the optimization property to Full Optimization (/Ox) compilerTool.Optimization = optimizeOption.optimizeFull; } else { Console.WriteLine(@"I Couldn't find the file"); } // Save the project, then remove it. project.ProjectFile = "MyNewProject.vcproj"; project.Save(); } else { Console.WriteLine(@"I Couldn't find the file collection"); } } else { Console.WriteLine(@"I Couldn't find the project"); } } catch (Exception e) { Console.WriteLine("Operation failed for the following reason: {0}", e.Message); } }
public static void SyncIncludeFiles(VCProject vcproj, List <string> priFiles, List <string> projFiles, DTE dte, bool flat, FakeFilter fakeFilter) { var cmpPriFiles = new List <string>(priFiles.Count); foreach (var s in priFiles) { cmpPriFiles.Add(HelperFunctions.NormalizeFilePath(s).ToLower()); } cmpPriFiles.Sort(); var cmpProjFiles = new List <string>(projFiles.Count); foreach (var s in projFiles) { cmpProjFiles.Add(HelperFunctions.NormalizeFilePath(s).ToLower()); } var qtPro = QtProject.Create(vcproj); var filterPathTable = new Hashtable(17); var pathFilterTable = new Hashtable(17); if (!flat && fakeFilter != null) { var rootFilter = qtPro.FindFilterFromGuid(fakeFilter.UniqueIdentifier); if (rootFilter == null) { qtPro.AddFilterToProject(Filters.SourceFiles()); } CollectFilters(rootFilter, null, ref filterPathTable, ref pathFilterTable); } // first check for new files foreach (var file in cmpPriFiles) { if (cmpProjFiles.IndexOf(file) > -1) { continue; } if (flat) { vcproj.AddFile(file); // the file is not in the project } else { var path = HelperFunctions.GetRelativePath(vcproj.ProjectDirectory, file); if (path.StartsWith(".\\", StringComparison.Ordinal)) { path = path.Substring(2); } var i = path.LastIndexOf('\\'); if (i > -1) { path = path.Substring(0, i); } else { path = "."; } if (pathFilterTable.Contains(path)) { var f = pathFilterTable[path] as VCFilter; f.AddFile(file); continue; } var filter = BestMatch(path, pathFilterTable); var filterDir = filterPathTable[filter] as string; var name = path; if (!name.StartsWith("..", StringComparison.Ordinal) && name.StartsWith(filterDir, StringComparison.Ordinal)) { name = name.Substring(filterDir.Length + 1); } var newFilter = filter.AddFilter(name) as VCFilter; newFilter.AddFile(file); filterPathTable.Add(newFilter, path); pathFilterTable.Add(path, newFilter); } } // then check for deleted files foreach (var file in cmpProjFiles) { if (cmpPriFiles.IndexOf(file) == -1) { // the file is not in the pri file // (only removes it from the project, does not del. the file) var info = new FileInfo(file); HelperFunctions.RemoveFileInProject(vcproj, file); Messages.PaneMessage(dte, "--- (Importing .pri file) file: " + info.Name + " does not exist in .pri file, move to " + vcproj.ProjectDirectory + "Deleted"); } } }