public void TestRenameOfNestedProject() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); IVsHierarchy nestedProjectHierarchy = Utilities.GetNestedHierarchy(project, "ANestedProject"); if (nestedProjectHierarchy == null) { throw new InvalidOperationException("The nested project has not been loaded corectly"); } // Get the id NestedProjectNode nestedProjectNode = Utilities.GetNodesOfType <NestedProjectNode>(project)[0]; project.SetProperty(nestedProjectNode.ID, (int)__VSHPROPID.VSHPROPID_EditLabel, "NewProject"); this.VerifyNestedProjectRename(project, nestedProjectNode, nestedProjectHierarchy, "NewProject"); // Now do an indirect rename through the property window. object extensibility; ErrorHandler.ThrowOnFailure(nestedProjectHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out extensibility)); EnvDTE.Project nestedAutomationProject = extensibility as EnvDTE.Project; EnvDTE.Property fileNameProperty = nestedAutomationProject.Properties.Item("FileName"); fileNameProperty.Value = "Project"; this.VerifyNestedProjectRename(project, nestedProjectNode, nestedProjectHierarchy, "Project"); }); }
public void TestConfigChange() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); EnvDTE.Property property = dte.Solution.Properties.Item("ActiveConfig"); // Now change the active config property.Value = "Release|x86"; // Force a designtime build to make sure the config change has been pushed through to the project project.GetProjectOptions(); MSBuild.Project buildProject = typeof(ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(project, new object[] { }) as MSBuild.Project; string activeConfig = null; buildProject.GlobalProperties.TryGetValue(GlobalProperty.Configuration.ToString(), out activeConfig); Assert.AreEqual("Release", activeConfig); }); }
public void TestAutomationOnProjectProperties() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); ProjectNode projectNode = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); //get the automation model of the project EnvDTE.Project project = projectNode.GetAutomationObject() as EnvDTE.Project; //get properties collection EnvDTE.Properties projectProperties = project.Properties; Assert.IsNotNull(projectProperties, "Could not get an instance of the project properties object"); //test the FullPath property returns the actual project path + project filename string fullPathFromProjectNode = projectNode.ProjectFolder + "\\"; EnvDTE.Property fullPath = projectProperties.Item(ProjectAutomationProperyNames.FullPath); Assert.IsFalse(String.IsNullOrEmpty(fullPath.Value.ToString()), "FullPath property is null or has not been assigned any value"); Assert.IsTrue(0 == String.Compare(fullPath.Value.ToString(), fullPathFromProjectNode, true), "FullPath property does not return the correct Value"); }); }
public void AddItemTemplateToProjectNew_ShouldReturnExpcted() { //Arange CodeInfo codeInfo = new CodeInfo() { Code = "code", Path = @"TestMethodName\TestFileName" }; string expectedFilePath = @"ServerMethods\TestMethodName\TestFileName.cs"; InitTestprojectStructure(); EnvDTE.Property specialMethodFolderFullPathProperty = Substitute.For <EnvDTE.Property>(); specialMethodFolderFullPathProperty.Value = @"ServerMethods\TestMethodName"; EnvDTE.Properties specialMethodFolderProperties = Substitute.For <EnvDTE.Properties>(); specialMethodFolderProperties.Item(Arg.Any <string>()).Returns(specialMethodFolderFullPathProperty); this.specialMethodFolder.Properties.Returns(specialMethodFolderProperties); this.specialMethodFolder.ProjectItems.AddFromFile(expectedFilePath).Returns(Substitute.For <ProjectItem>()); //Act string resultFilePath = this.projectManager.AddItemTemplateToProjectNew(codeInfo, false); //Assert Assert.AreEqual(expectedFilePath, resultFilePath); }
static public void SetGenerator(ProjectItem fileItem, string generatorName) { if (fileItem != null) { Properties fileProperties = fileItem.Properties; Debug.Assert(fileProperties != null, "SetCodeGeneratorProperty() - ProjectItem properties is NULL."); if (fileProperties != null) { EnvDTE.Property generatorProperty = fileProperties.Item("CustomTool"); Debug.Assert(generatorProperty != null, "SetCodeGeneratorProperty() - ProjectItem's Generator property is NULL."); if (generatorProperty != null) { try { generatorProperty.Value = generatorName; } catch (Exception e) { throw e; } } } } }
private async void BuildEvents_OnBuildDone(vsBuildScope Scope, vsBuildAction Action) { if (!UpdateManager.Current.IsConnected) { return; } try { await this.JoinableTaskFactory.SwitchToMainThreadAsync(this.DisposalToken); if (_mainDllProject != null && Scope == vsBuildScope.vsBuildScopeProject && Action == vsBuildAction.vsBuildActionBuild) { EnvDTE.Property property = _mainDllProject.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath"); string fullPath = _mainDllProject.Properties.Item("FullPath").Value.ToString(); string outputFileName = _mainDllProject.Properties.Item("OutputFileName").Value.ToString(); string outputPath = property.Value.ToString(); string assemblyPath = Path.Combine(fullPath, outputPath, outputFileName); using (MemoryStream ms = new MemoryStream()) { // Make a copy of the file into memory to avoid any file lock using (FileStream fs = File.OpenRead(assemblyPath)) await fs.CopyToAsync(ms); await UpdateManager.Current.SendAssemblyAsync(outputFileName, ms.ToArray()); if (_xamlCache.Count > 0) { // Force a xaml update for every page foreach (var cacheItem in _xamlCache) { await UpdateManager.Current.SendXamlAsync(cacheItem.Key, cacheItem.Value, true); } _xamlCache.Clear(); } _outputPane.OutputString("Requesting assembly update..."); _outputPane.OutputString(Environment.NewLine); } } } catch (Exception ex) { _outputPane.OutputString($"Something went wrong! RealXaml was unable to send the updated assembly."); _outputPane.OutputString(Environment.NewLine); _outputPane.OutputString(ex.ToString()); _outputPane.OutputString(Environment.NewLine); System.Diagnostics.Debug.WriteLine($"Something went wrong! RealXaml was unable to send the updated assembly."); System.Diagnostics.Debug.WriteLine(ex.ToString()); } this.IsBuilding = false; }
static string GetPropertyValue(EnvDTE.Property property) { if (property?.Value != null) { return(property.Value.ToString()); } return(string.Empty); }
/// <summary> /// Returns the full path of the assembly a project builds. /// </summary> /// <returns>The full path of the assembly this project builds.</returns> internal static string GetOutputPath(EnvDTE.Project automationProjectObject) { // Get the configuration manager from the project. EnvDTE.ConfigurationManager confManager = automationProjectObject.ConfigurationManager; if (null == confManager) { return(null); } // Get the active configuration. EnvDTE.Configuration config = confManager.ActiveConfiguration; if (null == config) { return(null); } // Get the output path for the current configuration. EnvDTE.Property outputPathProperty = config.Properties.Item("OutputPath"); if (null == outputPathProperty) { return(null); } string outputPath = outputPathProperty.Value.ToString(); // Ususally the output path is relative to the project path, but it is possible // to set it as an absolute path. If it is not absolute, then evaluate its value // based on the project directory. if (!System.IO.Path.IsPathRooted(outputPath)) { string projectDir = System.IO.Path.GetDirectoryName(automationProjectObject.FullName); outputPath = System.IO.Path.Combine(projectDir, outputPath); } // Now get the name of the assembly from the project. // Some project system throw if the property does not exist. We expect an ArgumentException. EnvDTE.Property assemblyNameProperty = null; try { assemblyNameProperty = automationProjectObject.Properties.Item("OutputFileName"); } catch (ArgumentException) { } if (null == assemblyNameProperty) { return(null); } else { outputPath = System.IO.Path.Combine(outputPath, assemblyNameProperty.Value.ToString()); } // build the full path adding the name of the assembly to the output path. return(outputPath); }
protected override void OnAfterGenerate() { base.OnAfterGenerate(); EnvDTE.Project project = EnvDTEHelper.Instance.GetProject(ProjectName); EnvDTE.Property preBuildProperty = project.Properties.Item("PreBuildEvent"); preBuildProperty.Value = "attrib -r \"$(SolutionDir)Bin\\*.*\""; EnvDTE.Property postBuildProperty = project.Properties.Item("PostBuildEvent"); postBuildProperty.Value = "copy \"$(TargetDir)$(TargetName).*\" \"$(SolutionDir)Bin\\\""; }
public NemerleContainedLanguage(IVsTextBufferCoordinator bufferCoordinator, NemerleIntellisenseProvider intellisenseProject, uint itemId, IVsHierarchy pHierarchy) { if (null == bufferCoordinator) { throw new ArgumentNullException("bufferCoordinator"); } if (null == intellisenseProject) { throw new ArgumentNullException("intellisenseProject"); } _hierarchy = pHierarchy; object projectItem = null; pHierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out projectItem); _projectItem = projectItem as EnvDTE.ProjectItem; EnvDTE.Property prop = _projectItem.Properties.Item("FullPath"); if (prop != null) { _filePath = prop.Value as string; } var project = _projectItem.ContainingProject as NemerleOAProject; if (project != null) { _projectInfo = ((NemerleProjectNode)project.Project).ProjectInfo; } _typeResolutionService = null; DynamicTypeService typeService = LanguageService.GetService(typeof(DynamicTypeService)) as DynamicTypeService; if (typeService != null) { _typeResolutionService = typeService.GetTypeResolutionService(this._hierarchy); } this.bufferCoordinator = bufferCoordinator; this.intellisenseProject = intellisenseProject; this.itemId = itemId; // Make sure that the secondary buffer uses the IronPython language service. IVsTextLines buffer; ErrorHandler.ThrowOnFailure(bufferCoordinator.GetSecondaryBuffer(out buffer)); Guid languageGuid; this.GetLanguageServiceID(out languageGuid); ErrorHandler.ThrowOnFailure(buffer.SetLanguageServiceID(ref languageGuid)); _documentClosingEventHandler = new _dispDocumentEvents_DocumentClosingEventHandler(OnDocumentClosing); }
private ConnectionStringSettings GetConnectionStringSettings(ProjectItem item, string name) { Property property = item.FindProperty(ProjectItemProperty.FullPath); var exeConfigurationFileMap = new ExeConfigurationFileMap { ExeConfigFilename = property.Value.ToString() }; Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(exeConfigurationFileMap, ConfigurationUserLevel.None); ConnectionStringsSection strings = configuration.ConnectionStrings; return(strings.ConnectionStrings[name]); }
/// <summary> /// Set the DisableErrorReporting property value. /// </summary> /// <param name="disable"> The property value to set. </param> private void DisableIntelliSenseErrorReport(bool disable) { DTE dte = _applicationObject as DTE; EnvDTE.Properties txtEdCpp = dte.get_Properties("TextEditor", "C/C++ Specific"); EnvDTE.Property prop = txtEdCpp.Item("DisableErrorReporting"); if (prop != null) { prop.Value = disable; } }
/// <summary> /// Sets a property value for the vs project item. /// </summary> public static void SetPropertyValue(EnvDTE.ProjectItem item, string propertyName, object value) { EnvDTE.Property property = item.Properties.Item(propertyName); if (property == null) { throw new ArgumentException(String.Format("The property {0} was not found.", propertyName)); } else { property.Value = value; } }
public NemerleSingleFileCodeModel(IVsHierarchy hierarchy, uint id, ProjectItem projectItem, CodeDomProvider codeDomProvider) : base(projectItem) { _codeDomProvider = codeDomProvider; _hierarchy = hierarchy; _id = id; EnvDTE.Property prop = ProjectItem.Properties.Item("FullPath"); if (prop != null) { _filePath = prop.Value as string; } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private async void Execute(object sender, EventArgs e) { try { // Switch to the main thread - the call to AddCommand in SendAssemblyCommand's constructor requires // the UI thread. await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(this.package.DisposalToken); var dte = await this.package.GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE; var projects = dte.ActiveSolutionProjects as Array; var project = projects.Cast <Project>().FirstOrDefault(); if (project == null) { return; } EnvDTE.Property property = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath"); string fullPath = project.Properties.Item("FullPath").Value.ToString(); string outputFileName = project.Properties.Item("OutputFileName").Value.ToString(); string outputPath = property.Value.ToString(); string assemblyPath = Path.Combine(fullPath, outputPath, outputFileName); using (MemoryStream ms = new MemoryStream()) { // Make a copy of the file into memory to avoid any file lock using (FileStream fs = File.OpenRead(assemblyPath)) await fs.CopyToAsync(ms); UpdateManager.Current.NotifyAssembly(outputFileName, ms.ToArray()); this.OutputPane?.OutputString("Requesting assembly update..."); this.OutputPane?.OutputString(Environment.NewLine); } } catch (Exception ex) { this.OutputPane?.OutputString($"Something went wrong! RealXaml was unable to send the updated assembly."); this.OutputPane?.OutputString(Environment.NewLine); this.OutputPane?.OutputString(ex.ToString()); this.OutputPane?.OutputString(Environment.NewLine); System.Diagnostics.Debug.WriteLine($"Something went wrong! RealXaml was unable to send the updated assembly."); System.Diagnostics.Debug.WriteLine(ex.ToString()); } //dte.Solution.SolutionBuild.BuildProject( // project.ConfigurationManager.ActiveConfiguration.ConfigurationName, // project.UniqueName); }
public static string GetValue(this EnvDTE.Properties source, string name) { string result = string.Empty; if (source == null || System.String.IsNullOrEmpty(name)) { return(result); } EnvDTE.Property property = source.Item(name); if (property != null) { return(property.Value.ToString()); } return(result); }
public void ProjectFinishedGenerating(Project project) { //MessageBox.Show("starting"); RegistryKey rk = Registry.LocalMachine; RegistryKey armSimKey = rk.OpenSubKey(@"SOFTWARE\University of Victoria\ARMSim.150"); if (armSimKey == null) { return; } string interfaceDLL = null; string installDirectory = null; using (armSimKey) { object obj = armSimKey.GetValue(@"Install Directory"); if (obj is string) { installDirectory = (string)obj; interfaceDLL = installDirectory + @"\ARMPluginInterfaces.dll"; } } if (installDirectory == null) { installDirectory = @"C:\Program Files\University of Victoria\ARMSim.150"; interfaceDLL = installDirectory + @"\ARMPluginInterfaces.dll"; } if (File.Exists(interfaceDLL)) { //EnvDTE.Project proj2 = (EnvDTE.Project)project.Object; VSLangProj.VSProject proj = (project.Object as VSLangProj.VSProject); proj.References.Add(interfaceDLL); proj.References.Add("System.Windows.Forms"); proj.References.Add("System.Drawing"); // config = proj.Project.ConfigurationManager.ActiveConfiguration; foreach (EnvDTE.Configuration config in proj.Project.ConfigurationManager) { EnvDTE.Properties configProps = config.Properties; EnvDTE.Property prop = configProps.Item("OutputPath"); prop.Value = installDirectory; } //foreach } } //ProjectFinishedGenerating
private static int BuildSolution(string fileName, bool convertToX86) { //Separate name of Solution string solutionName = FlatRedBall.IO.FileManager.RemovePath(fileName); //Register MessageFilter to prevent failed RPC messages MessageFilter.Register(); mInstance.Solution.Open(fileName); mInstance.Solution.SolutionBuild.SolutionConfigurations.Item("Debug").Activate(); object o = mInstance.Solution.SolutionBuild.ActiveConfiguration; if (convertToX86) { foreach (EnvDTE.Project proj in mInstance.Solution.Projects) { if (proj.ConfigurationManager == null) { continue; } System.Diagnostics.Trace.WriteLine(proj.Name); EnvDTE.Configuration config = proj.ConfigurationManager.ActiveConfiguration; EnvDTE.Property prop = config.Properties.Item("PlatformTarget"); prop.Value = "x86"; } } mInstance.Solution.SolutionBuild.Build(true); if (mInstance.Solution.SolutionBuild.LastBuildInfo == 0) { // instanceHandle.Quit(); // MessageFilter.Revoke(); return(0); } else { mInstance.MainWindow.Activate(); MessageFilter.Revoke(); return(mInstance.Solution.SolutionBuild.LastBuildInfo); } }
private void exploreXafErrors_Execute(ExecuteEventArgs ea) { Project startUpProject = CodeRush.ApplicationObject.Solution.FindStartUpProject(); Property outPut = startUpProject.ConfigurationManager.ActiveConfiguration.FindProperty(ConfigurationProperty.OutputPath); bool isWeb = IsWeb(startUpProject); string fullPath = startUpProject.FindProperty(ProjectProperty.FullPath).Value + ""; string path = Path.Combine(fullPath, outPut.Value.ToString()) + ""; if (isWeb) { path = Path.GetDirectoryName(startUpProject.FullName); } Func <Stream> streamSource = () => { var path1 = path + ""; File.Copy(Path.Combine(path1, "expressAppFrameWork.log"), Path.Combine(path1, "expressAppFrameWork.locked"), true); return(File.Open(Path.Combine(path1, "expressAppFrameWork.locked"), FileMode.Open, FileAccess.Read, FileShare.Read)); }; var reader = new ReverseLineReader(streamSource); var stackTrace = new List <string>(); foreach (var readline in reader) { stackTrace.Add(readline); if (readline.Trim().StartsWith("The error occured:") || readline.Trim().StartsWith("The error occurred:")) { stackTrace.Reverse(); string errorMessage = ""; foreach (string trace in stackTrace) { errorMessage += trace + Environment.NewLine; if (trace.Trim().StartsWith("----------------------------------------------------")) { break; } } Clipboard.SetText(errorMessage); break; } } }
public static object GetProperty(EnvDTE.Properties properties, string name) { if (properties == null || string.IsNullOrEmpty(name)) { return(null); } try { EnvDTE.Property property = properties.Cast <EnvDTE.Property>().FirstOrDefault(p => p.Name == name); if (property == null) { return(null); } return(property.Value); } catch (InvalidCastException) { return(null); } }
public void TestConfigChange() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); EnvDTE.Property property = dte.Solution.Properties.Item("ActiveConfig"); // Now chnange the active config that should trigger a project config change event and the global property should be thus updated. property.Value = "Release|Any CPU"; Microsoft.Build.BuildEngine.Project buildProject = typeof(ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(project, new object[] { }) as Microsoft.Build.BuildEngine.Project; string activeConfig = buildProject.GlobalProperties[GlobalProperty.Configuration.ToString()].Value; Assert.IsTrue(activeConfig == "Release"); }); }
private void UpdateProjectConfigurationsToUseRuleSetFile(EnvDTE.Project envDteProject, string fileName) { foreach (EnvDTE.Configuration config in envDteProject.ConfigurationManager) { EnvDTE.Properties properties = config.Properties; try { EnvDTE.Property codeAnalysisRuleSetFileProperty = properties?.Item("CodeAnalysisRuleSet"); if (codeAnalysisRuleSetFileProperty != null) { codeAnalysisRuleSetFileProperty.Value = fileName; } } catch (ArgumentException) { // Unfortunately the properties collection sometimes throws an ArgumentException // instead of returning null if the current configuration doesn't support CodeAnalysisRuleSet. // Ignore it and move on. } } }
public void TestConfigChange() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); EnvDTE.Property property = dte.Solution.Properties.Item("ActiveConfig"); // Now change the active config that should trigger a project config change event and the global property should be thus updated. property.Value = "Release|Any CPU"; MSBuildExecution.ProjectInstance buildProject = project.CurrentConfig; string activeConfig = null; buildProject.GlobalProperties.TryGetValue(GlobalProperty.Configuration.ToString(), out activeConfig); Assert.AreEqual("Release", activeConfig); }); }
public PropertyNodeFactory(EnvDTE.Property property) { _property = property; }
public void TestAutomationOnProjectItem() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); OAProject automation = Utilities.FindExtObject(sp, Utilities.NestedProjectGuid, TestContext.TestName) as OAProject; Assert.IsNotNull(automation, "Failed to create a project using automation"); ProjectNode project = automation.Project; // Get the AssemblyInfo.cs, try to open it and then ask using automation that it is opened. EnvDTE.ProjectItem item = automation.ProjectItems.Item("AssemblyInfo.cs"); Assert.IsNotNull(item, "Could not retrieve AssemblyInfo.cs"); EnvDTE.Window window = item.Open(VSConstants.LOGVIEWID_Primary.ToString()); Assert.IsNotNull(window, "Could not open the AssemblyInfo.cs"); window.Activate(); bool isOpen = item.get_IsOpen(VSConstants.LOGVIEWID_Primary.ToString()); Assert.IsTrue(isOpen, "The AssemblyInfo.cs file should have been opened"); // Now save it item.Save(""); Assert.IsTrue(item.Saved, "The renamed AssemblyInfo.cs has not been saved"); // Get the Document EnvDTE.Document document = item.Document; Assert.IsNotNull(document, "Could not retrieve the document object"); Assert.IsTrue(document.Name == "AssemblyInfo.cs", "The document for the file item is incorrect. It's name should be AssemblyInfo.cs"); // Try the properties on a nested item EnvDTE.ProjectItem nestedProject = automation.ProjectItems.Item("ANestedProject"); EnvDTE.ProjectItem nestedProjectItem = nestedProject.ProjectItems.Item("Program.cs"); EnvDTE.Properties nesteditemsProps = nestedProjectItem.Properties; EnvDTE.Property nestedItemProperty = nesteditemsProps.Item("BuildAction"); Assert.IsNotNull(nestedItemProperty, "Could not retrieve the BuildAction property from the nested project item"); nestedItemProperty.Value = BuildAction.Content; Assert.AreEqual((BuildAction)nestedItemProperty.Value, BuildAction.Content); // Now try the properties on the top project item EnvDTE.Properties props = item.Properties; Assert.IsNotNull(props, "Could not retrieve the BuildAction property from the nested project item"); EnvDTE.Property itemProperty = props.Item("BuildAction"); Assert.IsNotNull(itemProperty, "Could not retrieve the BuildAction property from the nested project item"); Assert.IsFalse(itemProperty is OANullProperty, "Could not retrieve the BuildAction property from the nested project item"); itemProperty.Value = BuildAction.Content; Assert.AreEqual(itemProperty.Value, BuildAction.Content); // Now save as Assert.IsTrue(item.SaveAs("AssemblyInfo1.cs"), "The file AssemblyInfo.cs could not be reanmed to AssemblyInfo1.cs"); Assert.IsTrue(item.Name == "AssemblyInfo1.cs", "File item has been renamed to AssemblyInfo1.cs but the Name property has not"); // Now try the Program.cs. That should not be opened EnvDTE.ProjectItem item1 = automation.ProjectItems.Item("Program.cs"); Assert.IsNotNull(item1, "Could not retrieve AssemblyInfo.cs"); isOpen = item1.get_IsOpen(VSConstants.LOGVIEWID_Primary.ToString()); Assert.IsFalse(isOpen, "The Program.cs should not have been opened"); // Now get the Reference folder as a project item and expand it. EnvDTE.ProjectItem references = automation.ProjectItems.Item("References"); references.ExpandView(); // Check that actually it was expanded. IVsUIHierarchyWindow uiHierarchy = VsShellUtilities.GetUIHierarchyWindow(project.Site, HierarchyNode.SolutionExplorer); System.Reflection.MethodInfo mi = typeof(ProjectNode).GetMethod("FindChild", BindingFlags.NonPublic | BindingFlags.Instance); ReferenceContainerNode containerNode = (ReferenceContainerNode)mi.Invoke(project, new object[] { "References" }); __VSHIERARCHYITEMSTATE state; uint stateAsInt; uiHierarchy.GetItemState(project, (uint)containerNode.ID, (uint)__VSHIERARCHYITEMSTATE.HIS_Expanded, out stateAsInt); state = (__VSHIERARCHYITEMSTATE)stateAsInt; Assert.IsTrue(state == __VSHIERARCHYITEMSTATE.HIS_Expanded, "The References folder has not been expanded"); }); }
public void TestInterfaceMethodsOnProperty() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); OAProject automation = Utilities.FindExtObject(sp, Utilities.NestedProjectGuid, TestContext.TestName) as OAProject; Assert.IsNotNull(automation, "Failed to create a project using automation"); ProjectNode projectNode = automation.Project; // Get Project Property object EnvDTE.Property property = automation.Properties.Item("RootNamespace"); Assert.IsNotNull(property, "Could not retrieve valid RootNamespace property"); Assert.IsFalse(property is OANullProperty, "Could not retrieve valid RootNamespace property"); object retValue = property.Application; Assert.IsNull(retValue); Assert.IsTrue((string)property.Value == "Application", "Failed to retrieve the Value property."); property.Value = "Test1"; Assert.AreEqual(property.Value, "Test1"); // Get Collection object from property object EnvDTE.Properties properties = property.Collection; Assert.IsNotNull(properties, "Collection property failed to retrieve an object"); // Get the DTE retValue = property.DTE; Assert.IsNotNull(retValue); // Get the Indexed value retValue = property.get_IndexedValue(1, 2, 3, 4); Assert.IsNull(retValue); property.let_Value(1); Assert.AreEqual(property.Value, "1"); // Check the name. string name = property.Name; Assert.IsNotNull(name); Assert.IsTrue(name == "RootNamespace", "RootNamespace property was not set correctly"); short numIndeces = property.NumIndices; //Currently it gives back 0 //It must be Assertd when the method changes Assert.IsTrue(numIndeces == 0); // Assert the Object property retValue = property.Object; Assert.AreEqual(retValue, property.Value); property.Object = "test1"; retValue = property.Object; Assert.AreEqual(retValue, "test1"); // Test the parent property EnvDTE.Properties parent = property.Parent; Assert.IsTrue(parent is OAProperties, "Parent property failed to return the parent of a property"); //It does nothing currently. Cannot be Assertd. property.set_IndexedValue(1, 2, 3, 4, 5); // Try a non string value on the Value. ArrayList list = new ArrayList(); property.Value = list; retValue = property.Value; Assert.AreEqual(retValue, list.ToString()); // Test the iterators for enumeration. // We are interested to see that we advance with the iteration. bool[] found = new bool[2]; foreach (EnvDTE.Property aProperty in automation.Properties) { if (aProperty.Name == "RootNamespace") { found[0] = true; } else if (aProperty.Name == "AssemblyName") { found[1] = true; } } foreach (bool foundValue in found) { Assert.IsTrue(foundValue, "The iterator on property collection has not been implemented correctly"); } }); }
/// <summary> /// Imports the specified obj. /// </summary> /// <param name="obj">The obj.</param> /// <param name="component">The component.</param> /// <param name="package">The package.</param> public static void Import(object obj, SoftwareComponent component, LayerPackage package) { MemoryStream ms = obj as MemoryStream; if (ms != null) { string projectInfo = String.Empty; String data = Encoding.Unicode.GetString(ms.ToArray()); StringBuilder sb = new StringBuilder(); for (int ix = 0; ix < data.Length; ix++) { char ch = data[ix]; if (ch == 0) { if (sb.Length > 2) { projectInfo = sb.ToString(); } if (sb.Length != 0) { sb = new StringBuilder(); } continue; } sb.Append(ch); } string[] infos = projectInfo.Split('|'); //// Comprend rien à la codification des noms de projet. //// //// Si contient un ., on prend le nom avant le / sinon c'est un site web, on //// prend le nom complet //string projectName = infos[1]; //if (projectName.IndexOf('.') > 0) //{ // int pos = projectName.LastIndexOf('\\'); // projectName = projectName.Substring(0, pos); //} Project prj = ServiceLocator.Instance.ShellHelper.FindProjectByName(infos[1]); if (prj != null) { using (Transaction transaction = component.Store.TransactionManager.BeginTransaction("Import layer")) { ImportProjectWizard wizard = new ImportProjectWizard(); if (wizard.ShowDialog() == DialogResult.OK) { SoftwareLayer layer = wizard.CreateLayer(component, package); string name = prj.Name; string[] parts = name.Split('\\'); if (parts.Length > 1) { name = parts[parts.Length - 2]; } layer.Name = name; layer.VSProjectName = name; // Récupération des propriétés for (int i = 0; i < prj.Properties.Count; i++) { EnvDTE.Property prop = prj.Properties.Item(i + 1); if (prop.Name == "RootNamespace") { layer.Namespace = prop.Value as string; } else if (prop.Name == "OutputFileName") { layer.AssemblyName = System.IO.Path.GetFileNameWithoutExtension(prop.Value as string); } } } transaction.Commit(); } } } }
public void ProjectItemFinishedGenerating(ProjectItem projectItem) { EnvDTE.Property property = projectItem.Properties.Item("TestFramework"); property.Value = _framework; }
private void SetDTEProperty(string category, string page, string item, object value) { EnvDTE.Properties props = appobj_.get_Properties(category, page); EnvDTE.Property prop = props.Item(item); prop.Value = value; }