public static EnvDTE.Project GetStartupProject(EnvDTE.DTE dte) { //获取当前启动调试项目(可能是右键启动新实例的项目,而非选择的启动项目) EnvDTE.Project activeProject = null; Array activeSolutionProjects = Babe.Lua.Package.BabePackage.Current.DTE.ActiveSolutionProjects as Array; if (activeSolutionProjects != null && activeSolutionProjects.Length > 0) { activeProject = activeSolutionProjects.GetValue(0) as EnvDTE.Project; if (activeProject != null && activeProject.Kind.ToUpper() == LuaProjectFactoryGuid) { return(activeProject); } } EnvDTE.SolutionBuild solutionBuild = dte.Solution.SolutionBuild; if (solutionBuild.StartupProjects == null) { return(null); } //当前启动项目是LuaProject,则返回该LuaProject string startupItem = ""; foreach (String item in (Array)solutionBuild.StartupProjects) { startupItem += item; } EnvDTE.Project startupProject = dte.Solution.Item(startupItem); if (startupProject != null && startupProject.Kind.ToUpper() == LuaProjectFactoryGuid) { return(startupProject); } //如果启动项不是LuaProject,则返回第一个LuaProject return(GetFirstLuaProject(dte)); /* * EnvDTE.Project activeProject = null; * Array activeSolutionProjects = LuaToolsPackage.Instance.DTE.ActiveSolutionProjects as Array; * if (activeSolutionProjects != null && activeSolutionProjects.Length > 0) * { * activeProject = activeSolutionProjects.GetValue(0) as EnvDTE.Project; * } * EnvDTE.Projects projects = LuaToolsPackage.Instance.DTE.Solution.Projects; * foreach(EnvDTE.Project project in projects) * { * string name = project.Name; * string extension = Path.GetExtension(project.FullName); * if (extension.ToLower() != ".luaproj") * continue; * } */ }
public override string GetResetScriptPath() { string initializationScriptRelativePath = InitializationScriptRelativePath.Replace('/', Path.DirectorySeparatorChar); string initializationScript; // Check folder with startup project path EnvDTE.SolutionBuild solutionBuild = VSContext.DTE.Solution.SolutionBuild; if (solutionBuild != null && solutionBuild.StartupProjects != null) { foreach (string item in (Array)solutionBuild.StartupProjects) { EnvDTE.Project project = VSContext.DTE.Solution.Projects.Item(item); string projectPath = project.FullName; string projectDirectory = projectPath; if (!Directory.Exists(projectPath)) { projectDirectory = Path.GetDirectoryName(projectPath); } initializationScript = Path.Combine(projectDirectory, initializationScriptRelativePath); if (File.Exists(initializationScript)) { return(initializationScript); } } } // Check folder with solution path string solutionPath = VSContext.DTE.Solution.FullName; string solutionDirectory = !Directory.Exists(solutionPath) ? Path.GetDirectoryName(solutionPath) : solutionPath; initializationScript = Path.Combine(solutionDirectory, initializationScriptRelativePath); if (File.Exists(initializationScript)) { return(initializationScript); } // Check current working directory initializationScript = Path.Combine(Directory.GetCurrentDirectory(), initializationScriptRelativePath); if (File.Exists(initializationScript)) { return(initializationScript); } // Base class anwser return(base.GetResetScriptPath()); }
/// <summary> /// Finds the dependencies between the projects in this solution. /// </summary><remarks> /// The dependencies are stored in the Solution.SolutionBuild.BuildDependencies /// object rather than in the projects themselves. So we need to parse them /// here rather than in the project parser. /// </remarks> private void parseDependencies() { // The dependencies for each project are stored in a BuildDependency object. // This holds a reference to the project, and references to all the projects // that it depends on (called 'required projects'). // We get the Solution.SolutionBuild.BuildDependencies object... EnvDTE.SolutionBuild solutionBuild = Utils.call(() => (m_dteSolution.SolutionBuild)); EnvDTE.BuildDependencies buildDependencies = Utils.call(() => (solutionBuild.BuildDependencies)); // We loop through the 'BuildDependencies'. Each one of these holds dependency // information for one project... int numBuildDependencies = Utils.call(() => (buildDependencies.Count)); for (int i = 1; i <= numBuildDependencies; ++i) { EnvDTE.BuildDependency buildDependency = Utils.call(() => (buildDependencies.Item(i))); // We get the project's name... EnvDTE.Project project = Utils.call(() => (buildDependency.Project)); string projectName = Utils.call(() => (project.Name)); // We loop through the required-projects, getting the name of each one... object[] requiredProjects = Utils.call(() => (buildDependency.RequiredProjects as object[])); int numRequiredProjects = requiredProjects.Length; for (int j = 0; j < numRequiredProjects; ++j) { EnvDTE.Project requiredProject = requiredProjects[j] as EnvDTE.Project; string requiredProjectName = Utils.call(() => (requiredProject.Name)); // We store the dependency with the parsed project... m_parsedSolution.addRequiredProjectToProject(projectName, requiredProjectName); } } // We set up any implicit linking that needs to be done because // of project dependencies (this may be needed for C++ projects)... m_parsedSolution.setupImplicitLinking(); // We set up references for C# projects... m_parsedSolution.setupReferences(); }
int IVsDeployableProjectCfg.StartDeploy(IVsOutputWindowPane pIVsOutputWindowPane, uint dwOptions) { int continueOn = 1; outputWindow = pIVsOutputWindowPane; if (connection != null) { lock (syncObject) { if (connection != null) { connection.Dispose(); connection = null; } } } // Loop through deploy status callbacks foreach (IVsDeployStatusCallback callback in deployCallbackCollection) { if (ErrorHandler.Failed(callback.OnStartDeploy(ref continueOn))) { continueOn = 0; } if (continueOn == 0) { outputWindow = null; return(VSConstants.E_ABORT); } } try { VsDebugTargetInfo2[] targets; uint deployFlags = (uint)(_AppContainerDeployOptions.ACDO_NetworkLoopbackEnable | _AppContainerDeployOptions.ACDO_SetNetworkLoopback); string recipeFile = null; string layoutDir = null; EnvDTE.DTE dte = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE)); EnvDTE.SolutionBuild sb = dte.Solution.SolutionBuild; string uniqueName = string.Empty; foreach (String s in (Array)sb.StartupProjects) { // There should only be one startup project so get the first one we find. uniqueName = s; break; } if (uniqueName.Equals(string.Empty)) { throw new Exception("Could not find a startup project to deploy."); } IVsSolution solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution)); IVsHierarchy hierarchy; solution.GetProjectOfUniqueName(uniqueName, out hierarchy); string canonicalName; IVsBuildPropertyStorage bps = hierarchy as IVsBuildPropertyStorage; int hr = QueryDebugTargets(out targets); if (ErrorHandler.Failed(hr)) { NotifyEndDeploy(0); return(hr); } get_CanonicalName(out canonicalName); bps.GetPropertyValue("AppxPackageRecipe", canonicalName, (uint)_PersistStorageType.PST_PROJECT_FILE, out recipeFile); bps.GetPropertyValue("LayoutDir", canonicalName, (uint)_PersistStorageType.PST_PROJECT_FILE, out layoutDir); string projectUniqueName = null; IVsSolution vsSolution = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution; if (vsSolution != null) { hr = vsSolution.GetUniqueNameOfProject((IVsHierarchy)this.project, out projectUniqueName); } PrepareNodeStartupInfo(uniqueName); System.IServiceProvider sp = this.project as System.IServiceProvider; IVsAppContainerProjectDeploy deployHelper = (IVsAppContainerProjectDeploy)sp.GetService(typeof(SVsAppContainerProjectDeploy)); if (String.IsNullOrEmpty(targets[0].bstrRemoteMachine)) { deployOp = deployHelper.StartDeployAsync(deployFlags, recipeFile, layoutDir, projectUniqueName, this); } else { IVsDebuggerDeploy deploy = (IVsDebuggerDeploy)sp.GetService(typeof(SVsShellDebugger)); IVsDebuggerDeployConnection deployConnection; bool useAuthentication = false; VsDebugRemoteAuthenticationMode am = useAuthentication ? VsDebugRemoteAuthenticationMode.VSAUTHMODE_WindowsAuthentication : VsDebugRemoteAuthenticationMode.VSAUTHMODE_None; hr = deploy.ConnectToTargetComputer(targets[0].bstrRemoteMachine, am, out deployConnection); if (ErrorHandler.Failed(hr)) { NotifyEndDeploy(0); return(hr); } connection = deployConnection; deployOp = deployHelper.StartRemoteDeployAsync(deployFlags, connection, recipeFile, projectUniqueName, this); } } catch (Exception) { if (connection != null) { lock (syncObject) { if (connection != null) { connection.Dispose(); connection = null; } } } connection = null; NotifyEndDeploy(0); throw; } return(VSConstants.S_OK); }