private VCFileConfiguration GetVCFileConfigForCompilation(Document document, out string reasonForFailure) { if (document == null) { reasonForFailure = "No document."; return(null); } var vcProject = document.ProjectItem.ContainingProject?.Object as VCProject; if (vcProject == null) { reasonForFailure = "The given document does not belong to a VC++ Project."; return(null); } VCFile vcFile = document.ProjectItem?.Object as VCFile; if (vcFile == null) { reasonForFailure = "The given document is not a VC++ file."; return(null); } if (vcFile.FileType != eFileType.eFileTypeCppCode) { reasonForFailure = "The given document is not a compileable VC++ file."; return(null); } IVCCollection fileConfigCollection = vcFile.FileConfigurations as IVCCollection; VCFileConfiguration fileConfig = fileConfigCollection?.Item(vcProject.ActiveConfiguration.Name) as VCFileConfiguration; if (fileConfig == null) { reasonForFailure = "Failed to retrieve file config from document."; return(null); } reasonForFailure = ""; return(fileConfig); }
static private void ParseSourceFile(StreamWriter streamWriter, IVCCollection files, Regex regex, int indent) { if (files.Count > 0) { for (int i = 1, n = files.Count; i <= n; ++i) { try { var file = files.Item(i) as VCFile; var path = file.RelativePath; if (regex == null || regex.Match(path).Success) { streamWriter.WriteLine(Indent(indent) + "{0}", path.Replace("\\", "/")); } } catch (System.Exception) { // maybe not a VCFile, that's why we dont use foreach, skip it } } } }
private static async Task <VCFileConfiguration> GetVCFileConfigForCompilation(Document document) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (document == null) { throw new VCQueryFailure("No document."); } var vcProject = document.ProjectItem?.ContainingProject?.Object as VCProject; if (vcProject == null) { throw new VCQueryFailure("The given document does not belong to a VC++ Project."); } VCFile vcFile = document.ProjectItem?.Object as VCFile; if (vcFile == null) { throw new VCQueryFailure("The given document is not a VC++ file."); } if (vcFile.FileType != eFileType.eFileTypeCppCode) { throw new VCQueryFailure("The given document is not a compileable VC++ file."); } IVCCollection fileConfigCollection = vcFile.FileConfigurations as IVCCollection; VCFileConfiguration fileConfig = fileConfigCollection?.Item(vcProject.ActiveConfiguration.Name) as VCFileConfiguration; if (fileConfig == null) { throw new VCQueryFailure("Failed to retrieve file config from document."); } return(fileConfig); }
/// <summary> /// Finds compiler settings, such as the include path, for the configuration /// passed in. /// </summary> private void parseConfiguration_CompilerSettings(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo) { // We get the compiler-settings 'tool'... IVCCollection tools = Utils.call(() => (vcConfiguration.Tools as IVCCollection)); VCCLCompilerTool compilerTool = Utils.call(() => (tools.Item("VCCLCompilerTool") as VCCLCompilerTool)); // And extract various details from it... parseCompilerSettings_IncludePath(vcConfiguration, compilerTool, configurationInfo); parseCompilerSettings_PreprocessorDefinitions(vcConfiguration, compilerTool, configurationInfo); parseCompilerSettings_CompilerFlags(vcConfiguration, compilerTool, configurationInfo); IVCCollection sheets = Utils.call(() => (vcConfiguration.PropertySheets as IVCCollection)); int numSheets = Utils.call(() => (sheets.Count)); for (int i = 1; i <= numSheets; ++i) { VCPropertySheet sheet = Utils.call(() => (sheets.Item(i) as VCPropertySheet)); if (!sheet.IsSystemPropertySheet) { // 1. The thing is that VCPropertySheet and VCConfiguration have more-or-less // identical interfaces. So we should be able to merge them fairly easily. // // 2. We should try multiple layers of inheritance IVCCollection toolsInSheet = Utils.call(() => (sheet.Tools as IVCCollection)); VCCLCompilerTool compilerToolInSheet = Utils.call(() => (toolsInSheet.Item("VCCLCompilerTool") as VCCLCompilerTool)); // And extract various details from it... if (compilerToolInSheet != null) { parseCompilerSettings_IncludePath(vcConfiguration, compilerToolInSheet, configurationInfo); parseCompilerSettings_PreprocessorDefinitions(vcConfiguration, compilerToolInSheet, configurationInfo); //parseCompilerSettings_CompilerFlags(vcConfiguration, compilerToolInSheet, configurationInfo); } } } }
/// <summary> /// Returns complete path user's executable file (including it's name). /// </summary> /// <returns>Output file path.</returns> private string GetFullOutputPath() { string fullPath = ""; string outputPath = ""; string outputFileName = ""; string primaryOutput = ""; foreach (EnvDTE.Project project in dte.Solution.Projects) { try // C++ { VCProject vcProject = (VCProject)(project.Object); IVCCollection configurations = (IVCCollection)vcProject.Configurations; VCConfiguration configuration = (VCConfiguration)configurations.Item("Debug"); primaryOutput = configuration.PrimaryOutput; return(primaryOutput); } catch { } try // C#, VB { fullPath = project.Properties.Item("FullPath").Value as string ?? ""; outputPath = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value as string ?? ""; outputFileName = project.Properties.Item("OutputFileName").Value as string ?? ""; return(fullPath + outputPath + outputFileName); } catch { } break; } throw new InvalidOperationException("Unable to retrieve the output file path."); }
public static string GetPCH(VCProject project, VCConfiguration config) { string pch = ""; IVCCollection tools = config.Tools as IVCCollection; VCCLCompilerTool vctool = tools.Item("VCCLCompilerTool") as VCCLCompilerTool; if (vctool != null) { pch = vctool.PrecompiledHeaderThrough; } if (pch != "") { VCFile file = Connect.GetVCFile(project, config.Evaluate(pch)); if (file != null) { pch = file.Name; } } return(pch); }
// ------------------------------------------------------ /// <summary> /// Add the CxxTest and Dereferee paths to the Visual C++ settings, /// if they aren't already there. /// </summary> private void AddIncludesAndLibrariesPaths() { DTE dte = (DTE)GetService(typeof(DTE)); Projects projects = (Projects)dte.GetObject("VCProjects"); VCProjectEngine projectEngine = (VCProjectEngine) projects.Properties.Item("VCProjectEngine").Object; IVCCollection platforms = (IVCCollection)projectEngine.Platforms; VCPlatform vcp = (VCPlatform)platforms.Item("Win32"); string packageDir = Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location); string cxxTestIncludePath = Path.Combine( packageDir, "Include\\cxxtest"); string derefereeIncludePath = Path.Combine( packageDir, "Include\\dereferee"); string supportLibPath = Path.Combine(packageDir, "Libraries"); string newIncludes = AddPathsToDirectories( vcp.IncludeDirectories, new string[] { cxxTestIncludePath, derefereeIncludePath }); vcp.IncludeDirectories = newIncludes; string newLibraries = AddPathsToDirectories( vcp.LibraryDirectories, new string[] { supportLibPath }); vcp.LibraryDirectories = newLibraries; vcp.CommitChanges(); }
/****************************************************************/ #endregion /* LifeCycle */ #region Public Operations /****************************************************************/ public void ParseVcproj() { //this specifies the name of the 'rm -f' or equivalent command string rm = "rm -f -v"; //this specifies the default name for the dependencies file string dependencies = ".dependencies"; string cflags = ""; string ldflags = ""; string libs = ""; m_MakFWriter.WriteLine("# Makefile - {0}", m_ProjectName); m_MakFWriter.WriteLine(); //get the project name dependencies = m_ProjectName + ".dep"; //catch the default configuration definition = first configuration in vcproj configurations m_MakFWriter.WriteLine("ifndef CFG"); m_MakFWriter.WriteLine("CFG={0}", ((VCConfiguration)m_ConfigCollection.Item(1)).ConfigurationName); m_MakFWriter.WriteLine("endif"); //print the C++ compiler definition m_MakFWriter.WriteLine("CC=gcc"); if (m_PlatfromName.Equals("Win32")) { m_MakFWriter.WriteLine("CFLAGS=-m32 -fpic"); } else { m_MakFWriter.WriteLine("CFLAGS=-m64 -fpic"); } m_MakFWriter.WriteLine("CXX=g++"); m_MakFWriter.WriteLine("CXXFLAGS=$(CFLAGS)"); #region Config Parsing /**********************************/ foreach (VCConfiguration config in m_ConfigCollection) { //print else for "$(CFG)" section in case it is not first config in makefile //if (0 != m_NumOfConfigs) //{ // m_MakFWriter.WriteLine("else"); //} //TODO:check this issue //print ifeq "$(CFG)" "CONFIG_NAME" m_MakFWriter.WriteLine("ifeq \"$(CFG)\" \"{0}\"", config.ConfigurationName); IVCCollection toolsCollection = (IVCCollection)config.Tools; #region VCCLCompilerTool /**********************************/ VCCLCompilerTool compTool = (VCCLCompilerTool)toolsCollection.Item("VCCLCompilerTool"); if (null != compTool) { cflags = iCreateCflags(compTool); //add special include path for VTOC files for (int i = 0; i < m_VcProjDependencies.Length; i++) { if (m_VcProjDependencies[i].Equals("v_to_c")) { cflags += " -I VTOC/share/include"; } } m_MakFWriter.WriteLine("CFLAGS+={0}", cflags); } /**********************************/ #endregion VCCLCompilerTool #region VCLinkerTool /**********************************/ VCLinkerTool lnkTool = (VCLinkerTool)toolsCollection.Item("VCLinkerTool"); if (null != lnkTool) { if ((m_TargetDictionary[config.ConfigurationName].ExeFlag) || (m_TargetDictionary[config.ConfigurationName].DllFlag)) { m_MakFWriter.WriteLine("LD=$(CXX) $(CXXFLAGS)"); } m_MakFWriter.WriteLine("LDFLAGS="); libs = iCreateLibs(lnkTool); ldflags = iCreateLdflags(lnkTool); m_MakFWriter.WriteLine("LDFLAGS+={0}", ldflags); if (m_TargetDictionary[config.ConfigurationName].ExeFlag) { m_MakFWriter.WriteLine("LIBS+={0}", libs); } if (m_TargetDictionary[config.ConfigurationName].DllFlag) { m_MakFWriter.WriteLine("LIBS+= -shared {0}", libs); } } /**********************************/ #endregion VCLinkerTool #region VCLibrarianTool /**********************************/ VCLibrarianTool libTool = (VCLibrarianTool)toolsCollection.Item("VCLibrarianTool"); if (null != libTool) { m_MakFWriter.WriteLine("AR=ar"); m_MakFWriter.WriteLine("ARFLAGS=rus"); } /**********************************/ #endregion VCLibrarianTool //print target for each configuration iPrintTARGET2Makefile(config.ConfigurationName); } //close every ifeq "$(CFG)" with endif for (int i = 0; i < m_NumOfConfigs; i++) { m_MakFWriter.WriteLine("endif"); } /**********************************/ #endregion Config Parsing //print default target for first configuration in configCollection iPrintTARGET2Makefile(((VCConfiguration)m_ConfigCollection.Item(1)).ConfigurationName); //print the default target and the suffix rules m_MakFWriter.WriteLine(".PHONY: all"); m_MakFWriter.WriteLine("all: $(TARGET)"); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("%.o: %.c"); m_MakFWriter.WriteLine("\t$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<"); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("%.o: %.cc"); m_MakFWriter.WriteLine("\t$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<"); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("%.o: %.cpp"); m_MakFWriter.WriteLine("\t$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<"); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("%.o: %.cxx"); m_MakFWriter.WriteLine("\t$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<"); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("%.res: %.rc"); m_MakFWriter.WriteLine("\t$(RC) $(CPPFLAGS) -o $@ -i $<"); m_MakFWriter.WriteLine(""); #region Sources /**********************************/ iPrintGroupsAndSources(); /**********************************/ #endregion Sources //define the objects automatically from the sources in the Makefile m_MakFWriter.WriteLine("OBJS=$(patsubst %.rc,%.res,$(patsubst %.cxx,%.o,$(patsubst %.cpp,%.o,$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(filter %.c %.cc %.cpp %.cxx %.rc,$(SRCS)))))))"); m_MakFWriter.WriteLine(""); //print the target rule, according to the type of deafult target = target of first configuration in vcproj configurations list m_MakFWriter.WriteLine("$(TARGET): $(OBJS)"); VcTargetType target = m_TargetDictionary[((VCConfiguration)m_ConfigCollection.Item(1)).ConfigurationName]; if (target.ExeFlag) { m_MakFWriter.WriteLine("\t$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)"); } if (target.DllFlag) { m_MakFWriter.WriteLine("\t$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)"); } if (target.LibFlag) { m_MakFWriter.WriteLine("\t$(AR) $(ARFLAGS) $@ $(OBJS)"); } m_MakFWriter.WriteLine(""); // print the 'clean' target rule m_MakFWriter.WriteLine(".PHONY: clean"); m_MakFWriter.WriteLine("clean:"); m_MakFWriter.WriteLine("\t-{0} $(OBJS) $(TARGET) {1}", rm, dependencies); m_MakFWriter.WriteLine(""); // print the 'depends' target rule for automatic dependencies generation m_MakFWriter.WriteLine(".PHONY: depends"); m_MakFWriter.WriteLine("depends:"); m_MakFWriter.WriteLine("\t-$(CXX) $(CXXFLAGS) $(CPPFLAGS) -MM $(filter %.c %.cc %.cpp %.cxx,$(SRCS)) > {0}", dependencies); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("-include {0}", dependencies); m_MakFWriter.WriteLine(""); m_MakFWriter.Close(); iFixMakfile(); }
private ProjectProperties GetProjectData() { ThreadHelper.ThrowIfNotOnUIThread(); Solution solution = GetActiveSolution(); if (solution == null) { return(null); } Project project = GetActiveProject(); if (project == null) { return(null); } VCProject prj = project.Object as VCProject; if (prj == null) { return(null); } VCConfiguration config = prj.ActiveConfiguration; if (config == null) { return(null); } VCPlatform platform = config.Platform; if (platform == null) { return(null); } var vctools = config.Tools as IVCCollection; if (vctools == null) { return(null); } var midl = vctools.Item("VCMidlTool") as VCMidlTool; ProjectProperties ret = new ProjectProperties(); ret.Target = midl != null && midl.TargetEnvironment == midlTargetEnvironment.midlTargetWin32 ? ProjectProperties.TargetType.x86 : ProjectProperties.TargetType.x64; //Working directory (always local to processed file) ret.WorkingDirectory = Path.GetDirectoryName(project.FullName); //TODO ~ ramonv ~ find a way to extract the /std value //Include dirs / files and preprocessor AppendMSBuildStringToList(ret.IncludeDirectories, platform.Evaluate(platform.IncludeDirectories)); AppendProjectProperties(ret, vctools.Item("VCCLCompilerTool") as VCCLCompilerTool, vctools.Item("VCNMakeTool") as VCNMakeTool, platform); try { //Get settings from the single file (this might fail badly if there are no settings to catpure) var applicationObject = ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2; Assumes.Present(applicationObject); ProjectItem item = applicationObject.ActiveDocument.ProjectItem; VCFile vcfile = item.Object as VCFile; IVCCollection fileCfgs = (IVCCollection)vcfile.FileConfigurations; VCFileConfiguration fileConfig = fileCfgs.Item(config.Name) as VCFileConfiguration; AppendProjectProperties(ret, fileConfig.Tool as VCCLCompilerTool, fileConfig.Tool as VCNMakeTool, platform); } catch (Exception) {} SolutionSettings customSettings = SettingsManager.Instance.Settings; if (customSettings != null) { AppendMSBuildStringToList(ret.IncludeDirectories, platform.Evaluate(customSettings.AdditionalIncludeDirs)); AppendMSBuildStringToList(ret.ForceIncludes, platform.Evaluate(customSettings.AdditionalForceIncludes)); AppendMSBuildStringToList(ret.PrepocessorDefinitions, platform.Evaluate(customSettings.AdditionalPreprocessorDefinitions)); ret.ExtraArguments = platform.Evaluate(customSettings.AdditionalCommandLine); ret.ShowWarnings = customSettings.EnableWarnings; } //Exclude directories RemoveMSBuildStringFromList(ret.IncludeDirectories, platform.Evaluate(platform.ExcludeDirectories)); return(ret); }
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 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"); } }
private void CreateConfigForEachFile(ref VCProject actVCP, List <string> additionalParamsList, string BuildMode) { Log("\tFile Specific Configuration"); IVCCollection filesCollection = (IVCCollection)actVCP.Files; if (filesCollection != null) { for (int item_idx = 0; item_idx < filesCollection.Count + 1; ++item_idx) { try { VCFile file = (VCFile)(filesCollection.Item(item_idx)); if (file != null) { try { // Preprocessed headers VCFileConfiguration fileConfiguration = (VCFileConfiguration)(((IVCCollection)file.FileConfigurations).Item(BuildMode)); // Access the release configuration of this file. VCCLCompilerTool compilerTool = (VCCLCompilerTool)fileConfiguration.Tool; // Get the compiler tool associated with this file. switch (compilerTool.UsePrecompiledHeader) { case pchOption.pchCreateUsingSpecific: break; case pchOption.pchUseUsingSpecific: case pchOption.pchNone: if (compilerTool.UsePrecompiledHeader != pchOption.pchNone) { compilerTool.UsePrecompiledHeader = pchOption.pchNone; Log("\t\tPrecompiled headers are deactivated for the file '" + file.Name + "'"); if (compilerTool.PrecompiledHeaderThrough != null) { string directoryToAppend = System.IO.Path.GetDirectoryName(compilerTool.PrecompiledHeaderThrough); if (appendToAdditionalDirectories(ref compilerTool, directoryToAppend)) { Log("\t\tAdditional of '" + directoryToAppend + "'a in the list of additional include directories for the file '" + file.Name + "'"); } } } if (compilerTool.AdditionalOptions == null) { compilerTool.AdditionalOptions = " "; } string additionalParams = generateParamString(additionalParamsList, compilerTool.AdditionalOptions); if (additionalParams.Length > 0) { compilerTool.AdditionalOptions += " " + additionalParams; Log("\t\tAdditional command line arguments '" + additionalParams + "' are appended for the file '" + file.Name + "'"); } break; } } catch (Exception e) { Debug(e); } } } catch (Exception e) { Debug(e); } } } }
public override ProjectProperties GetProjectData() { ThreadHelper.ThrowIfNotOnUIThread(); OutputLog.Log("Capturing configuration from VS projects..."); Project project = EditorUtils.GetActiveProject(); VCProject prj = project.Object as VCProject; if (prj == null) { return(null); } VCConfiguration config = prj.ActiveConfiguration; if (config == null) { return(null); } VCPlatform platform = config.Platform; if (platform == null) { return(null); } var vctools = config.Tools as IVCCollection; if (vctools == null) { return(null); } var midl = vctools.Item("VCMidlTool") as VCMidlTool; var evaluator = new MacroEvaluatorVisualPlatform(platform); ProjectProperties ret = new ProjectProperties(); ret.Target = midl != null && midl.TargetEnvironment == midlTargetEnvironment.midlTargetWin32 ? ProjectProperties.TargetType.x86 : ProjectProperties.TargetType.x64; ret.Standard = GetStandardVersion(config); //Working directory (always local to processed file) ret.WorkingDirectory = Path.GetDirectoryName(project.FullName); //Include dirs / files and preprocessor AppendMSBuildStringToList(ret.IncludeDirectories, evaluator.Evaluate(platform.IncludeDirectories)); AppendProjectProperties(ret, vctools.Item("VCCLCompilerTool") as VCCLCompilerTool, vctools.Item("VCNMakeTool") as VCNMakeTool, evaluator); //Get settings from the single file (this might fail badly if there are no settings to catpure) var applicationObject = EditorUtils.ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2; Assumes.Present(applicationObject); ProjectItem item = applicationObject.ActiveDocument.ProjectItem; VCFile vcfile = item != null ? item.Object as VCFile : null; IVCCollection fileCfgs = vcfile != null ? (IVCCollection)vcfile.FileConfigurations : null; VCFileConfiguration fileConfig = fileCfgs != null?fileCfgs.Item(config.Name) as VCFileConfiguration : null; VCCLCompilerTool fileToolCL = null; VCNMakeTool fileToolNMake = null; try { fileToolCL = fileConfig.Tool as VCCLCompilerTool; fileToolNMake = fileConfig.Tool as VCNMakeTool; } catch (Exception e) { //If we really need this data we can always parse the vcxproj as an xml OutputLog.Log("File specific properties not found, only project properties used (" + e.Message + ")"); } AppendProjectProperties(ret, fileToolCL, fileToolNMake, evaluator); CaptureExtraProperties(ret, evaluator); AddCustomSettings(ret, evaluator); RemoveMSBuildStringFromList(ret.IncludeDirectories, evaluator.Evaluate(platform.ExcludeDirectories)); //Exclude directories ProcessPostProjectData(ret); return(ret); }
private void ProjectContextMenuItemCallback(object sender, EventArgs e) { var dte = this.dte.DTE; OutputWindow outputWindow = null; try { outputWindow = new OutputWindow(dte); OleMenuCommand menuCommand = sender as OleMenuCommand; if (menuCommand != null && dte != null) { Array selectedProjects = (Array)dte.ActiveSolutionProjects; //only support 1 selected project if (selectedProjects.Length == 1) { EnvDTE.Project project = (EnvDTE.Project)selectedProjects.GetValue(0); var vcproj = project.Object as VCProject; if (vcproj != null) { IVCCollection configs = (IVCCollection)vcproj.Configurations; VCConfiguration cfg = (VCConfiguration)vcproj.ActiveConfiguration; VCDebugSettings debug = (VCDebugSettings)cfg.DebugSettings; string command = null; string arguments = null; string workingDirectory = null; if (debug != null) { command = cfg.Evaluate(debug.Command); workingDirectory = cfg.Evaluate(debug.WorkingDirectory); arguments = cfg.Evaluate(debug.CommandArguments); } VCPlatform currentPlatform = (VCPlatform)cfg.Platform; string platform = currentPlatform == null ? null : currentPlatform.Name; if (platform != null) { platform = platform.ToLower(); if (platform.Contains("x64")) { platform = "x64"; } else if (platform.Contains("x86") || platform.Contains("win32")) { platform = "x86"; } else { throw new NotSupportedException("Platform is not supported."); } } else { cfg = (VCConfiguration)configs.Item("Debug|x64"); platform = "x64"; if (cfg == null) { throw new NotSupportedException("Cannot find x64 platform for project."); } } if (command == null || String.IsNullOrEmpty(command)) { command = cfg.PrimaryOutput; } if (command != null) { var solutionFolder = System.IO.Path.GetDirectoryName(dte.Solution.FileName); CoverageExecution executor = new CoverageExecution(dte, outputWindow); executor.Start( solutionFolder, platform, System.IO.Path.GetDirectoryName(command), System.IO.Path.GetFileName(command), workingDirectory, arguments); } } } } } catch (NotSupportedException ex) { if (outputWindow != null) { outputWindow.WriteLine("Error running coverage: {0}", ex.Message); } } catch (Exception ex) { if (outputWindow != null) { outputWindow.WriteLine("Unexpected code coverage failure; error: {0}", ex.ToString()); } } }
/****************************************************************/ #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="; }
private void Initialize( EnvDTE.Project prj ) { project = (VCProject)prj.Object; configurations = (IVCCollection)project.Configurations; EnvDTE.ConfigurationManager configManager = prj.ConfigurationManager; EnvDTE.Configuration activeConfig = configManager.ActiveConfiguration; string activeConfigNamePlatform = activeConfig.ConfigurationName + "|" + activeConfig.PlatformName; foreach (VCConfiguration c in project.Configurations) { if (c.Name == activeConfigNamePlatform) { config = c; break; } } Debug.Assert(config != null); if (config == null) throw new InvalidOperationException("The specified file does not have a configuration corresponding to the current active configuration."); //config = (VCConfiguration)configurations.Item(1); tools = (IVCCollection)config.Tools; cltool = (VCCLCompilerTool)tools.Item("VCCLCompilerTool"); }
private const int timeoutMS = 30000; // 30 seconds public static VCFileConfiguration GetFileConfig(EnvDTE.Document document, out string reasonForFailure, out bool isHeader) { isHeader = false; if (document == null) { reasonForFailure = "No document."; return(null); } string unityPath = document.Path; unityPath = System.IO.Path.Combine(unityPath, "unity"); var project = document.ProjectItem?.ContainingProject; VCProject vcProject = project.Object as VCProject; if (vcProject == null) { reasonForFailure = "The given document does not belong to a VC++ Project."; return(null); } VCFile vcFile = document.ProjectItem?.Object as VCFile; if (vcFile == null) { reasonForFailure = "The given document is not a VC++ file."; return(null); } VCFilter vcFolder = vcFile.Parent as VCFilter; if (vcFolder == null) { reasonForFailure = "Can't get folder for VC++ file."; return(null); } // Replace file with unity file with the same path foreach (VCFile file in vcFolder.Items) { if (file != null) { if (System.IO.Path.GetFileName(file.FullPath).StartsWith("unity_")) { vcFile = file; break; } } } if (vcFile == null) { reasonForFailure = "The given document is not a VC++ file."; return(null); } isHeader = vcFile.FileType == Microsoft.VisualStudio.VCProjectEngine.eFileType.eFileTypeCppHeader; IVCCollection fileConfigCollection = vcFile.FileConfigurations; VCFileConfiguration fileConfig = fileConfigCollection?.Item(vcProject.ActiveConfiguration.Name); if (fileConfig == null) { reasonForFailure = "Failed to retrieve file config from document."; return(null); } reasonForFailure = ""; return(fileConfig); }