public void ConfigProperties() { using (PackageTestEnvironment testEnv = new PackageTestEnvironment()) { IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage; Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage."); // Get (2 different configs) string propertyName = "ConfigProperty"; string value = null; int hr = buildProperty.GetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual("DebugValue", value); hr = buildProperty.GetPropertyValue(propertyName, "Release", (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual("ReleaseValue", value); // Set (with get to confirm) string newValue = "UpdatedConfig"; hr = buildProperty.SetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, newValue); Assert.AreEqual <int>(VSConstants.S_OK, hr, "SetPropertyValue failed"); hr = buildProperty.GetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual(newValue, value); } }
public void ConfigProperties() { using(PackageTestEnvironment testEnv = new PackageTestEnvironment()) { IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage; Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage."); // Get (2 different configs) string propertyName = "ConfigProperty"; string value = null; int hr = buildProperty.GetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual<int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual("DebugValue", value); hr = buildProperty.GetPropertyValue(propertyName, "Release", (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual<int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual("ReleaseValue", value); // Set (with get to confirm) string newValue = "UpdatedConfig"; hr = buildProperty.SetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, newValue); Assert.AreEqual<int>(VSConstants.S_OK, hr, "SetPropertyValue failed"); hr = buildProperty.GetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual<int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual(newValue, value); } }
public void GlobalProperties() { using (PackageTestEnvironment testEnv = new PackageTestEnvironment()) { IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage; Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage."); // Get string propertyName = "GlobalProperty"; string value = null; int hr = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual("Global", value); // Set (with get to confirm) string newValue = "UpdatedGlobal"; hr = buildProperty.SetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, newValue); Assert.AreEqual <int>(VSConstants.S_OK, hr, "SetPropertyValue failed"); hr = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual(newValue, value); // Remove (with get to confirm) hr = buildProperty.RemoveProperty(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE); Assert.AreEqual <int>(VSConstants.S_OK, hr, "RemoveProperty failed"); hr = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual(String.Empty, value); } }
public void FileProperties() { using (PackageTestEnvironment testEnv = new PackageTestEnvironment()) { PropertyInfo buildProjectInfo = typeof(VisualStudio.Project.ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic); Microsoft.Build.Evaluation.Project buildProject = buildProjectInfo.GetValue(testEnv.Project, new object[0]) as Microsoft.Build.Evaluation.Project; // Add a node to the project map so it can be resolved IEnumerable <Microsoft.Build.Evaluation.ProjectItem> itemGroup = buildProject.GetItems("Compile"); Microsoft.Build.Evaluation.ProjectItem item = null; foreach (Microsoft.Build.Evaluation.ProjectItem currentItem in itemGroup) { if (currentItem.EvaluatedInclude == "OtherFile.cs") { item = currentItem; break; } } VisualStudio.Project.FileNode node = new VisualStudio.Project.FileNode(testEnv.Project, testEnv.Project.GetProjectElement(item)); MethodInfo itemMapGetter = typeof(VisualStudio.Project.ProjectNode).GetProperty("ItemIdMap", BindingFlags.Instance | BindingFlags.NonPublic).GetGetMethod(true); Microsoft.VisualStudio.Shell.EventSinkCollection itemMap = (Microsoft.VisualStudio.Shell.EventSinkCollection)itemMapGetter.Invoke(testEnv.Project, new object[0]); uint itemID = itemMap.Add(node); IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage; Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage."); // Get string propertyName = "Metadata"; string value = null; int hr = buildProperty.GetItemAttribute(itemID, propertyName, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetItemAttribute failed"); Assert.AreEqual("OtherFileProperty", value); // Set (with get to confirm) string newValue = "UpdatedFileProperty"; hr = buildProperty.SetItemAttribute(itemID, propertyName, newValue); Assert.AreEqual <int>(VSConstants.S_OK, hr, "SetPropertyValue failed"); hr = buildProperty.GetItemAttribute(itemID, propertyName, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetItemAttribute failed"); Assert.AreEqual(newValue, value); } }
public void FileProperties() { using(PackageTestEnvironment testEnv = new PackageTestEnvironment()) { PropertyInfo buildProjectInfo = typeof(VisualStudio.Project.ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic); Microsoft.Build.BuildEngine.Project buildProject = buildProjectInfo.GetValue(testEnv.Project, new object[0]) as Microsoft.Build.BuildEngine.Project; // Add a node to the project map so it can be resolved Microsoft.Build.BuildEngine.BuildItemGroup itemGroup = buildProject.GetEvaluatedItemsByName("Compile"); Microsoft.Build.BuildEngine.BuildItem item = null; foreach(Microsoft.Build.BuildEngine.BuildItem currentItem in itemGroup) { if(currentItem.FinalItemSpec == "OtherFile.cs") { item = currentItem; break; } } VisualStudio.Project.FileNode node = new VisualStudio.Project.FileNode(testEnv.Project, testEnv.Project.GetProjectElement(item)); MethodInfo itemMapGetter = typeof(VisualStudio.Project.ProjectNode).GetProperty("ItemIdMap", BindingFlags.Instance | BindingFlags.NonPublic).GetGetMethod(true); Microsoft.VisualStudio.Shell.EventSinkCollection itemMap = (Microsoft.VisualStudio.Shell.EventSinkCollection)itemMapGetter.Invoke(testEnv.Project, new object[0]); uint itemID = itemMap.Add(node); IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage; Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage."); // Get string propertyName = "Metadata"; string value = null; int hr = buildProperty.GetItemAttribute(itemID, propertyName, out value); Assert.AreEqual<int>(VSConstants.S_OK, hr, "GetItemAttribute failed"); Assert.AreEqual("OtherFileProperty", value); // Set (with get to confirm) string newValue = "UpdatedFileProperty"; hr = buildProperty.SetItemAttribute(itemID, propertyName, newValue); Assert.AreEqual<int>(VSConstants.S_OK, hr, "SetPropertyValue failed"); hr = buildProperty.GetItemAttribute(itemID, propertyName, out value); Assert.AreEqual<int>(VSConstants.S_OK, hr, "GetItemAttribute failed"); Assert.AreEqual(newValue, value); } }
public void FileProperties() { using(PackageTestEnvironment testEnv = new PackageTestEnvironment()) { Microsoft.Build.Evaluation.Project buildProject = testEnv.Project.BuildProject; // Add a node to the project map so it can be resolved IEnumerable<Microsoft.Build.Evaluation.ProjectItem> itemGroup = buildProject.GetItems("Compile"); Microsoft.Build.Evaluation.ProjectItem item = null; foreach (Microsoft.Build.Evaluation.ProjectItem currentItem in itemGroup) { if(currentItem.EvaluatedInclude == "OtherFile.cs") { item = currentItem; break; } } VisualStudio.Project.FileNode node = new VisualStudio.Project.FileNode(testEnv.Project, testEnv.Project.GetProjectElement(item)); uint itemID = node.Id; IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage; Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage."); // Get string propertyName = "Metadata"; string value = null; int hr = buildProperty.GetItemAttribute(itemID, propertyName, out value); Assert.AreEqual<int>(VSConstants.S_OK, hr, "GetItemAttribute failed"); Assert.AreEqual("OtherFileProperty", value); // Set (with get to confirm) string newValue = "UpdatedFileProperty"; hr = buildProperty.SetItemAttribute(itemID, propertyName, newValue); Assert.AreEqual<int>(VSConstants.S_OK, hr, "SetPropertyValue failed"); hr = buildProperty.GetItemAttribute(itemID, propertyName, out value); Assert.AreEqual<int>(VSConstants.S_OK, hr, "GetItemAttribute failed"); Assert.AreEqual(newValue, value); } }
public void FileProperties() { using (PackageTestEnvironment testEnv = new PackageTestEnvironment()) { Microsoft.Build.Evaluation.Project buildProject = testEnv.Project.BuildProject; // Add a node to the project map so it can be resolved IEnumerable <Microsoft.Build.Evaluation.ProjectItem> itemGroup = buildProject.GetItems("Compile"); Microsoft.Build.Evaluation.ProjectItem item = null; foreach (Microsoft.Build.Evaluation.ProjectItem currentItem in itemGroup) { if (currentItem.EvaluatedInclude == "OtherFile.cs") { item = currentItem; break; } } VisualStudio.Project.FileNode node = new VisualStudio.Project.FileNode(testEnv.Project, testEnv.Project.GetProjectElement(item)); uint itemID = node.Id; IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage; Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage."); // Get string propertyName = "Metadata"; string value = null; int hr = buildProperty.GetItemAttribute(itemID, propertyName, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetItemAttribute failed"); Assert.AreEqual("OtherFileProperty", value); // Set (with get to confirm) string newValue = "UpdatedFileProperty"; hr = buildProperty.SetItemAttribute(itemID, propertyName, newValue); Assert.AreEqual <int>(VSConstants.S_OK, hr, "SetPropertyValue failed"); hr = buildProperty.GetItemAttribute(itemID, propertyName, out value); Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetItemAttribute failed"); Assert.AreEqual(newValue, value); } }
public void GlobalProperties() { using(PackageTestEnvironment testEnv = new PackageTestEnvironment()) { IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage; Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage."); // Get string propertyName = "GlobalProperty"; string value = null; int hr = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual<int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual("Global", value); // Set (with get to confirm) string newValue = "UpdatedGlobal"; hr = buildProperty.SetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, newValue); Assert.AreEqual<int>(VSConstants.S_OK, hr, "SetPropertyValue failed"); hr = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual<int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual(newValue, value); // Remove (with get to confirm) hr = buildProperty.RemoveProperty(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE); Assert.AreEqual<int>(VSConstants.S_OK, hr, "RemoveProperty failed"); hr = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); Assert.AreEqual<int>(VSConstants.S_OK, hr, "GetPropertyValue failed"); Assert.AreEqual(String.Empty, value); } }