public CProject2008(string name, string file) : base(name, file) { m_vcProject = null; m_projectDir = Path.GetDirectoryName(file); if (s_engine == null) { s_engine = new VCProjectEngineObject(); } }
static void PrintPlatforms(VCProjectEngineObject engine) { foreach (VCPlatform p in engine.Platforms as IVCCollection) { Console.WriteLine($"<{p.Name}>"); Console.WriteLine($"IncludeDirectories:{p.IncludeDirectories}"); Console.WriteLine($"ExecutableDirectories:{p.ExecutableDirectories}"); Console.WriteLine($"LibraryDirectories:{p.LibraryDirectories}"); Console.WriteLine($"SourceDirectories:{p.SourceDirectories}"); Console.WriteLine($"ExcludeDirectories:{p.ExcludeDirectories}"); for (var i = 0; i < p.NumberOfPlatformMacros; i++) { WriteLine($"PlatformMacro:{p.PlatformMacro[i]}"); } foreach (var tool in p.Tools as IVCCollection) { switch (tool) { case VCLinkerTool linkerTool: break; case VCLibrarianTool librarianTool: break; case VCCLCompilerTool compilerTool: Console.WriteLine(compilerTool.toolName); break; case VCCustomBuildTool customBuildTool: break; case VCResourceCompilerTool resourceCompilerTool: break; } } } }
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); } }
static async Task <int> MainAsync(ProgramOptions options) { var engine = new VCProjectEngineObject(); if (options.PrintPlatforms) { PrintPlatforms(engine); return(0); } var dir = Path.GetDirectoryName(options.ProjectFilePath); var baseJsonPath = Path.Combine(dir, "compile_commands.base.json"); var baseObj = File.Exists(baseJsonPath) ? JsonSerializer.Deserialize <FileCompilationInfo>(File.ReadAllBytes(baseJsonPath)) : new FileCompilationInfo(); if (baseObj.arguments != null && baseObj.command != null) { Console.Error.WriteLine("You must specify either `arguments` or `command` in compile_commands.base.json. "); return(2); } baseObj.directory = dir; var output = new List <FileCompilationInfo>(); var project = engine.LoadProject(options.ProjectFilePath) as VCProject; if (project == null) { Console.Error.WriteLine("Invalid project file."); return(3); } //var buildTarget = "Release|Win32"; //var buildTarget = "Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)"; var buildTarget = options.BuildTarget; foreach (VCFile file in project.Files) { var fileConfigurations = file.FileConfigurations as IVCCollection; VCFileConfiguration fileConfig = fileConfigurations.Item(buildTarget); if (fileConfig == null) { Console.Error.WriteLine($"warning: Build Target [{buildTarget}] Not Found for `{file.Name}`"); continue; } var platform = buildTarget.Split('|')[1]; var m = new Regex(@"\((\w+)\)").Match(platform); var arch = platform == "Win64" ? "x86_64" : m.Success ? m.Groups[1].Value.ToLower() : "i386"; var entry = ProcessVCFile(options, baseObj.Clone(), file, fileConfig, arch, platform == "Win64"); if (entry != null) { output.Add(entry); } } if (options.OnlyConvertToUtf8) { return(0); } using (var stream = File.OpenWrite(Path.Combine(dir, CompileCommandsJson))) { stream.SetLength(0); await JsonSerializer.SerializeAsync(stream, output, new JsonSerializerOptions() { WriteIndented = true, IgnoreNullValues = true, }); } return(0); }
/// <summary> /// Returns true if the given platform is available in the global settings of Visual Studio. /// On error this function returns false. /// </summary> public static bool IsPlatformAvailable(EnvDTE.DTE dteObject, string platformName) { if (availablePlatforms == null || availablePlatforms.Count == 0) { availablePlatforms = new List<string>(); #if VS2005 // Read the available platforms from WCE.VCPlatform.config // instead of using VCProjectEngine, because the project wizards aren't // able to list the platforms if VS2005 is used. String vcPlatformCfg = dteObject.FullName; int idx = vcPlatformCfg.LastIndexOf("\\"); idx = vcPlatformCfg.LastIndexOf("\\", idx - 1); idx = vcPlatformCfg.LastIndexOf("\\", idx - 1); vcPlatformCfg = vcPlatformCfg.Substring(0, idx + 1); vcPlatformCfg += "VC\\vcpackages\\WCE.VCPlatform.config"; FileStream stream = new FileStream(vcPlatformCfg, FileMode.Open); XmlReader reader = new XmlTextReader(stream); while (reader.ReadToFollowing("PlatformName")) { availablePlatforms.Add(reader.ReadElementContentAsString()); } #else VCProjectEngine engine = new VCProjectEngineObject(); IVCCollection platforms = engine.Platforms as IVCCollection; foreach (VCPlatform platform in platforms) { availablePlatforms.Add(platform.Name); } #endif } if (availablePlatforms == null) return false; return availablePlatforms.Contains(platformName); }
public void CreateTestCocoonConfig(String config, string project, List <string> additionalParamsList, List <string> additiona_includes, bool QtConfiguration) { bool foundProject = false; IEnumerator ProjectsEnumaror = GetVCProjectRefs(); ProjectsEnumaror.Reset(); // traverse all projects to find the right one while (ProjectsEnumaror.MoveNext()) { VCProject actVCP = (VCProject)ProjectsEnumaror.Current; if (actVCP.Name == project) { foundProject = true; VCConfiguration vcC = null; //vcC = (VCConfiguration)(((IVCCollection)actVCP.Configurations).Item(config)); IEnumerator ConfigurationEnumarator = ((IVCCollection)actVCP.Configurations).GetEnumerator(); for (ConfigurationEnumarator.Reset(); ConfigurationEnumarator.MoveNext();) { vcC = ConfigurationEnumarator.Current as VCConfiguration; if ((vcC != null) && (vcC.ConfigurationName == config)) { Log("Modifying configuration '" + config + "' for the project '" + project + "' for the platform '" + vcC.Name + "'"); // change settings for sepcified compiler IVCCollection ctools = (IVCCollection)vcC.Tools; VCActiveXReference cVCActiveXReference = ctools.Item("VCActiveXReference") as VCActiveXReference; VCALinkTool cVCALinkTool = ctools.Item("VCALinkTool") as VCALinkTool; VCAppVerifierTool cVCAppVerifierTool = ctools.Item("VCAppVerifierTool") as VCAppVerifierTool; VCAssemblyReference cVCAssemblyReference = ctools.Item("VCAssemblyReference") as VCAssemblyReference; VCBscMakeTool cVCBscMakeTool = ctools.Item("VCBscMakeTool") as VCBscMakeTool; VCCLCompilerTool cVCCLCompilerTool = ctools.Item("VCCLCompilerTool") as VCCLCompilerTool; VCConfiguration cVCConfiguration = ctools.Item("VCConfiguration") as VCConfiguration; VCCustomBuildRule cVCCustomBuildRule = ctools.Item("VCCustomBuildRule") as VCCustomBuildRule; VCCustomBuildTool cVCCustomBuildTool = ctools.Item("VCCustomBuildTool") as VCCustomBuildTool; VCDebugSettings cVCDebugSettings = ctools.Item("VCDebugSettings") as VCDebugSettings; VCFile cVCFile = ctools.Item("VCFile") as VCFile; VCFileConfiguration cVCFileConfiguration = ctools.Item("VCFileConfiguration") as VCFileConfiguration; VCFilter cVCFilter = ctools.Item("VCFilter") as VCFilter; VCFxCopTool cVCFxCopTool = ctools.Item("VCFxCopTool") as VCFxCopTool; VCLibrarianTool cVCLibrarianTool = ctools.Item("VCLibrarianTool") as VCLibrarianTool; VCLinkerTool cVCLinkerTool = ctools.Item("VCLinkerTool") as VCLinkerTool; VCManagedResourceCompilerTool cVCManagedResourceCompilerTool = ctools.Item("VCManagedResourceCompilerTool") as VCManagedResourceCompilerTool; VCManifestTool cVCManifestTool = ctools.Item("VCManifestTool") as VCManifestTool; VCMidlTool cVCMidlTool = ctools.Item("VCMidlTool") as VCMidlTool; VCNMakeTool cVCNMakeTool = ctools.Item("VCNMakeTool") as VCNMakeTool; VCPlatform cVCPlatform = ctools.Item("VCPlatform") as VCPlatform; VCPostBuildEventTool cVCPostBuildEventTool = ctools.Item("VCPostBuildEventTool") as VCPostBuildEventTool; VCPreBuildEventTool cVCPreBuildEventTool = ctools.Item("VCPreBuildEventTool") as VCPreBuildEventTool; VCPreLinkEventTool cVCPreLinkEventTool = ctools.Item("VCPreLinkEventTool") as VCPreLinkEventTool; VCProject cVCProject = ctools.Item("VCProject") as VCProject; VCProjectEngine cVCProjectEngine = ctools.Item("VCProjectEngine") as VCProjectEngine; VCProjectEngineEvents cVCProjectEngineEvents = ctools.Item("VCProjectEngineEvents") as VCProjectEngineEvents; VCProjectEngineObject cVCProjectEngineObject = ctools.Item("VCProjectEngineObject") as VCProjectEngineObject; VCProjectItem cVCProjectItem = ctools.Item("VCProjectItem") as VCProjectItem; VCProjectReference cVCProjectReference = ctools.Item("VCProjectReference") as VCProjectReference; VCPropertySheet cVCPropertySheet = ctools.Item("VCPropertySheet") as VCPropertySheet; VCReference cVCReference = ctools.Item("VCReference") as VCReference; VCReferences cVCReferences = ctools.Item("VCReferences") as VCReferences; VCResourceCompilerTool cVCResourceCompilerTool = ctools.Item("VCResourceCompilerTool") as VCResourceCompilerTool; VCRuntimeBooleanProperty cVCRuntimeBooleanProperty = ctools.Item("VCRuntimeBooleanProperty") as VCRuntimeBooleanProperty; VCRuntimeEnumProperty cVCRuntimeEnumProperty = ctools.Item("VCRuntimeEnumProperty") as VCRuntimeEnumProperty; VCRuntimeEnumValue cVCRuntimeEnumValue = ctools.Item("VCRuntimeEnumValue") as VCRuntimeEnumValue; VCRuntimeIntegerProperty cVCRuntimeIntegerProperty = ctools.Item("VCRuntimeIntegerProperty") as VCRuntimeIntegerProperty; VCRuntimeProperty cVCRuntimeProperty = ctools.Item("VCRuntimeProperty") as VCRuntimeProperty; VCRuntimeStringProperty cVCRuntimeStringProperty = ctools.Item("VCRuntimeStringProperty") as VCRuntimeStringProperty; VCToolFile cVCToolFile = ctools.Item("VCToolFile") as VCToolFile; VCUserMacro cVCUserMacro = ctools.Item("VCUserMacro") as VCUserMacro; VCWebDeploymentTool cVCWebDeploymentTool = ctools.Item("VCWebDeploymentTool") as VCWebDeploymentTool; VCWebServiceProxyGeneratorTool cVCWebServiceProxyGeneratorTool = ctools.Item("VCWebServiceProxyGeneratorTool") as VCWebServiceProxyGeneratorTool; VCXDCMakeTool cVCXDCMakeTool = ctools.Item("VCXDCMakeTool") as VCXDCMakeTool; VCXMLDataGeneratorTool cVCXMLDataGeneratorTool = ctools.Item("VCXMLDataGeneratorTool") as VCXMLDataGeneratorTool; VCLinkerTool linkerTool = ctools.Item("VCLinkerTool") as VCLinkerTool; VCLibrarianTool librarianTool = ctools.Item("VCLibrarianTool") as VCLibrarianTool; VCCLCompilerTool compilerTool = ctools.Item("VCCLCompilerTool") as VCCLCompilerTool; VCCustomBuildTool customBuildTool = ctools.Item("VCCustomBuildTool") as VCCustomBuildTool; string libgen = FindCslibConfig(ref compilerTool); List <string> additionalParamsListLink = new List <string>(additionalParamsList); List <string> additionalParamsListLibrarian = new List <string>(additionalParamsList); if (libgen != null) { additionalParamsListLink.Add("--cs-libgen=" + libgen); additionalParamsListLibrarian.Add("--cs-libgen=" + libgen); } if (compilerTool != null) { CreateClConfig(ref compilerTool, additionalParamsList, additiona_includes, actVCP.ProjectDirectory, config); } if (linkerTool != null) { CreateLinkConfig(ref linkerTool, additionalParamsListLink, config); } if (customBuildTool != null) { CreateCustomBuildConfig(ref customBuildTool, additionalParamsList, config); } if (librarianTool != null) { CreateLibrarianConfig(ref librarianTool, additionalParamsListLibrarian, config); } if (actVCP != null) { CreateConfigForEachFile(ref actVCP, additionalParamsList, config); } } } } } if (!foundProject) { ShowMessageBox("Could not find the project", "Warning"); } }
/****************************************************************/ #endregion /* Members */ #region LifeCycle /****************************************************************/ public VcProjInfo(string vcProjFile, string outFile, string[] projDependencies) { Console.WriteLine("Going to read project file '{0}'", vcProjFile); Console.WriteLine("aiming to write result to file '{0}'", outFile); if (projDependencies.GetLength(0) <= 0) { Console.WriteLine("With no dependencies."); } else { Console.WriteLine("With dependencies:"); foreach (String s in projDependencies) { Console.WriteLine("\t" + s); } //projDependencies.ToString()); } Console.WriteLine(""); // to visually separate output. //Init project name and .mak file name m_ProjectName = Path.GetFileNameWithoutExtension(vcProjFile); m_MakeFileName = outFile; m_VcProjDependencies = projDependencies; VCProjectEngine vcprojEngine = new VCProjectEngineObject(); try { //Init VCProject vcProj object m_VcProj = (VCProject)vcprojEngine.LoadProject(vcProjFile); } catch (Exception ex) { Console.WriteLine("Some errors occurred during project loading: {0}\n\n\n", ex.Message); Console.WriteLine("This tool knows to convert Visual Studio 2005 projects only\n"); Console.WriteLine("For converting Visual Studio 2008 projects, compile this tool on VS2008 \n"); Console.WriteLine("add Microsoft.VisualStudio.VCProjectEngine9.0.0 reference\n"); } //Init vcproj configurations list m_ConfigCollection = (IVCCollection)m_VcProj.Configurations; //Init targets dictionary (Key is configuration name, Value is VcTargetType object m_TargetDictionary = new Dictionary <string, VcTargetType>(); foreach (VCConfiguration config in m_ConfigCollection) { m_TargetDictionary.Add(config.ConfigurationName, new VcTargetType(config)); } //Init number of vcProj configurations m_NumOfConfigs = m_ConfigCollection.Count; //Init platform name of vcProj IVCCollection platformCollection = (IVCCollection)m_VcProj.Platforms; VCPlatform platform = (VCPlatform)platformCollection.Item(1); m_PlatfromName = platform.Name; //Init Filters collection m_FileFilterCollection = (IVCCollection)m_VcProj.Filters; Console.WriteLine("Creating file " + m_MakeFileName + "..."); //Open StreamWriter for writing into makFileName m_MakFWriter = new StreamWriter(m_MakeFileName); m_SRCGroups = "SRCS="; }