public static MsBuildProject Load(string pathToProject) { if (!File.Exists(pathToProject)) { return(null); } MsBuildProject project = new MsBuildProject(); project[Files.Project].filePath = pathToProject; if (!LoadXml(project[Files.Project])) { return(null); } project[Files.Filters].filePath = pathToProject + ".filters"; if (File.Exists(project[Files.Filters].filePath) && !LoadXml(project[Files.Filters])) { return(null); } project[Files.User].filePath = pathToProject + ".user"; if (File.Exists(project[Files.User].filePath) && !LoadXml(project[Files.User])) { return(null); } return(project); }
private void ImportQMakeProject(FileInfo projectFile, VersionInformation vi) { var xmlProject = MsBuildProject.Load(projectFile.FullName); var qtDir = ParseQtDirFromFileContent(xmlProject.ProjectXml, vi); if (!string.IsNullOrEmpty(qtDir)) { xmlProject.ReplacePath(qtDir, "$(QTDIR)\\"); // qmake tends to write relative and absolute paths into the .vcxproj file if (!Path.IsPathRooted(qtDir)) // if the project is on the same drive as Qt. { xmlProject.ReplacePath(vi.qtDir + '\\', "$(QTDIR)\\"); } } else { Messages.PaneMessage(dteObject, SR.GetString("ImportProject_CannotFindQtDirectory", projectFile.Name)); } xmlProject.ReplacePath(projectFile.DirectoryName, "."); xmlProject.AddQtMsBuildReferences(); xmlProject.ConvertCustomBuildToQtMsBuild(); xmlProject.EnableMultiProcessorCompilation(); #if (VS2017 || VS2015) string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion(); if (!string.IsNullOrEmpty(versionWin10SDK)) { xmlProject.SetDefaultWindowsSDKVersion(versionWin10SDK); } #endif xmlProject.Save(); }
private void ImportQMakeProject(FileInfo projectFile, VersionInformation vi) { var xmlProject = MsBuildProject.Load(projectFile.FullName); xmlProject.ReplacePath(vi.qtDir, "$(QTDIR)"); xmlProject.ReplacePath(projectFile.DirectoryName, "."); bool ok = xmlProject.AddQtMsBuildReferences(); if (ok) { ok = xmlProject.ConvertCustomBuildToQtMsBuild(); } if (ok) { ok = xmlProject.EnableMultiProcessorCompilation(); } #if (VS2019 || VS2017 || VS2015) if (ok) { string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion(); if (!string.IsNullOrEmpty(versionWin10SDK)) { ok = xmlProject.SetDefaultWindowsSDKVersion(versionWin10SDK); } } #endif if (ok) { ok = xmlProject.UpdateProjectFormatVersion(); } if (!ok) { Messages.PaneMessage(dteObject, SR.GetString("ImportProject_CannotConvertProject", projectFile.Name)); } xmlProject.Save(); // Initialize Qt variables xmlProject.BuildTarget("QtVarsDesignTime"); }
private VersionInformation(string qtDirIn) { qtDir = qtDirIn; try { var qmakeQuery = new QMakeQuery(this); SetupPlatformSpecificData(qmakeQuery); // Find version number var strVersion = qmakeQuery["QT_VERSION"]; if (!string.IsNullOrEmpty(strVersion)) { var versionParts = strVersion.Split('.'); if (versionParts.Length != 3) { qtDir = null; return; } qtMajor = uint.Parse(versionParts[0]); qtMinor = uint.Parse(versionParts[1]); qtPatch = uint.Parse(versionParts[2]); } else { var inF = new StreamReader(Locate_qglobal_h()); var rgxpVersion = new Regex("#define\\s*QT_VERSION\\s*0x(?<number>\\d+)", RegexOptions.Multiline); var contents = inF.ReadToEnd(); inF.Close(); var matchObj = rgxpVersion.Match(contents); if (!matchObj.Success) { qtDir = null; return; } strVersion = matchObj.Groups[1].ToString(); var version = Convert.ToUInt32(strVersion, 16); qtMajor = version >> 16; qtMinor = (version >> 8) & 0xFF; qtPatch = version & 0xFF; } qt5Version = (qtMajor == 5); try { QtInstallDocs = qmakeQuery["QT_INSTALL_DOCS"]; } catch { } } catch { qtDir = null; return; } // Get VS project settings try { var tempProData = new StringBuilder(); tempProData.AppendLine("SOURCES = main.cpp"); var modules = QtModules.Instance.GetAvailableModuleInformation() .Where((QtModuleInfo mi) => mi.Selectable); foreach (QtModuleInfo mi in modules) { tempProData.AppendLine(string.Format( "qtHaveModule({0}): HEADERS += {0}.h", mi.proVarQT)); } var randomName = Path.GetRandomFileName(); var tempDir = Path.Combine(Path.GetTempPath(), randomName); Directory.CreateDirectory(tempDir); var tempPro = Path.Combine(tempDir, string.Format("{0}.pro", randomName)); File.WriteAllText(tempPro, tempProData.ToString()); var qmake = new QMakeImport(this, tempPro); qmake.DisableWarnings = true; qmake.Run(setVCVars: true); var tempVcxproj = Path.Combine(tempDir, string.Format("{0}.vcxproj", randomName)); var msbuildProj = MsBuildProject.Load(tempVcxproj); Directory.Delete(tempDir, recursive: true); var availableModules = msbuildProj.GetItems("ClInclude") .Select((string s) => Path.GetFileNameWithoutExtension(s)); _IsModuleAvailable = modules.ToDictionary( (QtModuleInfo mi) => mi.proVarQT, (QtModuleInfo mi) => availableModules.Contains(mi.proVarQT)); VC_MinimumVisualStudioVersion = msbuildProj.GetProperty("MinimumVisualStudioVersion"); VC_ApplicationTypeRevision = msbuildProj.GetProperty("ApplicationTypeRevision"); VC_WindowsTargetPlatformVersion = msbuildProj.GetProperty("WindowsTargetPlatformVersion"); VC_WindowsTargetPlatformMinVersion = msbuildProj.GetProperty("WindowsTargetPlatformMinVersion"); VC_PlatformToolset = msbuildProj.GetProperty("PlatformToolset"); VC_Link_TargetMachine = msbuildProj.GetProperty("Link", "TargetMachine"); } catch (Exception e) { throw new QtVSException("Error reading VS project settings", e); } }