本文整理汇总了C#中Microsoft.VisualStudioTools.VisualStudioApp类的典型用法代码示例。如果您正苦于以下问题:C# VisualStudioApp类的具体用法?C# VisualStudioApp怎么用?C# VisualStudioApp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VisualStudioApp类属于Microsoft.VisualStudioTools命名空间,在下文中一共展示了VisualStudioApp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ActivateInteractiveWindow
public override ToolWindowPane ActivateInteractiveWindow(VisualStudioApp app, string executionMode) {
string description = null;
if (Version.IsCPython) {
description = string.Format("{0} {1}",
Version.Isx64 ? "Python 64-bit" : "Python 32-bit",
Version.Version.ToVersion()
);
} else if (Version.IsIronPython) {
description = string.Format("{0} {1}",
Version.Isx64 ? "IronPython 64-bit" : "IronPython",
Version.Version.ToVersion()
);
}
Assert.IsNotNull(description, "Unknown interpreter");
var automation = (IVsPython)app.Dte.GetObject("VsPython");
var options = (IPythonOptions)automation;
var replOptions = options.Interactive;
Assert.IsNotNull(replOptions, "Could not find options for " + description);
var oldAddNewLineAtEndOfFullyTypedWord = options.Intellisense.AddNewLineAtEndOfFullyTypedWord;
app.OnDispose(() => options.Intellisense.AddNewLineAtEndOfFullyTypedWord = oldAddNewLineAtEndOfFullyTypedWord);
options.Intellisense.AddNewLineAtEndOfFullyTypedWord = AddNewLineAtEndOfFullyTypedWord;
var interpreters = app.ComponentModel.GetService<IInterpreterRegistryService>();
var replId = PythonReplEvaluatorProvider.GetEvaluatorId(
interpreters.FindConfiguration(Version.Id)
);
return app.ServiceProvider.GetUIThread().Invoke(() => {
var provider = app.ComponentModel.GetService<InteractiveWindowProvider>();
return (ToolWindowPane)provider.OpenOrCreate(replId);
});
}
示例2: FromProcessId
public static VisualStudioApp FromProcessId(int processId) {
VisualStudioApp inst;
lock (_knownInstances) {
if (!_knownInstances.TryGetValue(processId, out inst)) {
_knownInstances[processId] = inst = new VisualStudioApp(processId);
}
}
return inst;
}
示例3: OpenProject
internal void OpenProject(VisualStudioApp app, string slnName, out PythonProjectNode projectNode, out EnvDTE.Project dteProject) {
PythonVersion.AssertInstalled();
dteProject = app.OpenProject("TestData\\Targets\\" + slnName);
projectNode = dteProject.GetPythonProject();
var fact = projectNode.InterpreterFactories.Where(x => x.Configuration.Id == PythonVersion.Id).FirstOrDefault();
Assert.IsNotNull(fact, "Project does not contain expected interpreter");
projectNode.ActiveInterpreter = fact;
dteProject.Save();
}
示例4: CreateTemporaryProject
private EnvDTE.Project CreateTemporaryProject(VisualStudioApp app) {
var project = app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.PythonApplicationTemplate,
TestData.GetTempPath(),
TestContext.TestName
);
Assert.IsNotNull(project, "Project was not created");
return project;
}
示例5: TestNpmUIInitialization
public void TestNpmUIInitialization() {
using (var app = new VisualStudioApp()) {
// Initialize call is required because NTVS does not autoload its package
// We may not be on UI thread, but Dev11 and Dev12 know how to sort that out.
app.ServiceProvider.GetUIThread().Invoke(() => {
NpmPackageInstallWindow npmWindow = OpenNpmWindowAndWaitForReady();
Assert.IsTrue(npmWindow.FilterTextBox.IsKeyboardFocused, "FilterTextBox should be keyboard focused");
Assert.AreEqual(0, npmWindow._packageList.SelectedIndex, "First item in package list should be selected");
});
}
}
示例6: NpmUIArrowKeyBehavior
public void NpmUIArrowKeyBehavior()
{
using (var app = new VisualStudioApp()) {
app.ServiceProvider.GetUIThread().Invoke(() => {
NpmPackageInstallWindow npmWindow = OpenNpmWindowAndWaitForReady();
System.Windows.Input.Keyboard.Focus(npmWindow.FilterTextBox);
TestUtilities.UI.Keyboard.PressAndRelease(Key.Down);
WaitForUIInputIdle();
var selectedItem = GetSelectedPackageListItemContainer(npmWindow);
Assert.IsTrue(selectedItem.IsKeyboardFocused, "Focus should be on newly selected item");
Assert.AreEqual(0, npmWindow._packageList.SelectedIndex);
TestUtilities.UI.Keyboard.PressAndRelease(Key.Down);
WaitForUIInputIdle();
Assert.AreEqual(1, npmWindow._packageList.SelectedIndex);
npmWindow.FilterTextBox.Focus();
TestUtilities.UI.Keyboard.PressAndRelease(Key.Up);
WaitForUIInputIdle();
Assert.IsTrue(npmWindow.FilterTextBox.IsKeyboardFocused, "Focus should remain on filter box");
Assert.AreEqual(1, npmWindow._packageList.SelectedIndex, "Pressing up while in filter box should maintain current selection");
selectedItem = GetSelectedPackageListItemContainer(npmWindow);
selectedItem.Focus();
TestUtilities.UI.Keyboard.PressAndRelease(Key.Up);
TestUtilities.UI.Keyboard.PressAndRelease(Key.Up);
WaitForUIInputIdle();
Assert.IsTrue(npmWindow.FilterTextBox.IsKeyboardFocused, "Focus should move to filter textbox after pressing up key while on topmost package is selected");
TestUtilities.UI.Keyboard.PressAndRelease(Key.Up);
WaitForUIInputIdle();
Assert.IsTrue(npmWindow.FilterTextBox.IsKeyboardFocused, "Focus should remain on textbox while pressing up when topmost package is selected");
Assert.IsFalse(npmWindow.InstallButton.IsEnabled, "Install button should not be enabled when filter box has focus");
TestUtilities.UI.Keyboard.PressAndRelease(Key.Enter);
WaitForUIInputIdle();
selectedItem = GetSelectedPackageListItemContainer(npmWindow);
Assert.IsTrue(selectedItem.IsKeyboardFocused, "Focus should be on newly selected item");
Assert.AreEqual(0, npmWindow._packageList.SelectedIndex);
});
}
}
示例7: FromCommandLineArgs
public static VisualStudioApp FromCommandLineArgs(string[] commandLineArgs) {
for (int i = 0; i < commandLineArgs.Length - 1; ++i) {
int processId;
if (commandLineArgs[i].Equals("/parentProcessId", StringComparison.InvariantCultureIgnoreCase) &&
int.TryParse(commandLineArgs[i + 1], out processId)) {
VisualStudioApp inst;
lock (_knownInstances) {
if (!_knownInstances.TryGetValue(processId, out inst)) {
_knownInstances[processId] = inst = new VisualStudioApp(processId);
}
}
return inst;
}
}
return null;
}
示例8: NewDjangoProject
public void NewDjangoProject() {
using (var app = new VisualStudioApp()) {
var project = app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.DjangoWebProjectTemplate,
TestData.GetTempPath(),
"NewDjangoProject"
);
var folder = project.ProjectItems.Item(project.Name);
Assert.IsNotNull(project.ProjectItems.Item("manage.py"));
Assert.IsNotNull(folder.ProjectItems.Item("settings.py"));
Assert.IsNotNull(folder.ProjectItems.Item("urls.py"));
Assert.IsNotNull(folder.ProjectItems.Item("__init__.py"));
Assert.IsNotNull(folder.ProjectItems.Item("wsgi.py"));
}
}
示例9: NewDjangoProjectSafeProjectName
public void NewDjangoProjectSafeProjectName() {
using (var app = new VisualStudioApp()) {
var project = app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.DjangoWebProjectTemplate,
TestData.GetTempPath(),
"Django Project $100"
);
var folder = project.ProjectItems.Item("Django_Project__100");
Assert.IsNotNull(project.ProjectItems.Item("manage.py"));
Assert.IsNotNull(folder.ProjectItems.Item("settings.py"));
Assert.IsNotNull(folder.ProjectItems.Item("urls.py"));
Assert.IsNotNull(folder.ProjectItems.Item("__init__.py"));
Assert.IsNotNull(folder.ProjectItems.Item("wsgi.py"));
var settings = app.ServiceProvider.GetUIThread().Invoke(() => project.GetPythonProject().GetProperty("DjangoSettingsModule"));
Assert.AreEqual("Django_Project__100.settings", settings);
}
}
示例10: TestAttachBasic
public void TestAttachBasic() {
string debugSolution = TestData.GetPath(@"TestData\DebugAttach\DebugAttach.sln");
string startFile = "Simple.py";
using (var app = new VisualStudioApp()) {
var dbg2 = (Debugger2)app.Dte.Debugger;
SD.Process processToAttach = OpenSolutionAndLaunchFile(app, debugSolution, startFile, "", "");
try {
AttachAndWaitForMode(app, processToAttach, AD7Engine.DebugEngineName, dbgDebugMode.dbgRunMode);
} finally {
dbg2.DetachAll();
DebugProject.WaitForMode(app, dbgDebugMode.dbgDesignMode);
if (!processToAttach.HasExited) processToAttach.Kill();
}
}
}
示例11: CustomCommandsAdded
public void CustomCommandsAdded() {
using (var app = new VisualStudioApp()) {
PythonProjectNode node;
EnvDTE.Project proj;
OpenProject(app, "Commands1.sln", out node, out proj);
AssertUtil.ContainsExactly(
node._customCommands.Select(cc => cc.DisplayLabel),
"Test Command 1",
"Test Command 2"
);
app.OpenSolutionExplorer().FindItem("Solution 'Commands1' (1 project)", "Commands1").Select();
var menuBar = app.FindByAutomationId("MenuBar").AsWrapper();
Assert.IsNotNull(menuBar, "Unable to find menu bar");
var projectMenu = menuBar.FindByName("Project").AsWrapper();
Assert.IsNotNull(projectMenu, "Unable to find Project menu");
projectMenu.Element.EnsureExpanded();
try {
foreach (var name in node._customCommands.Select(cc => cc.DisplayLabelWithoutAccessKeys)) {
Assert.IsNotNull(projectMenu.FindByName(name), name + " not found");
}
} finally {
try {
// Try really really hard to collapse and deselect the
// Project menu, since VS will keep it selected and it
// may not come back for some reason...
projectMenu.Element.Collapse();
Keyboard.PressAndRelease(System.Windows.Input.Key.Escape);
Keyboard.PressAndRelease(System.Windows.Input.Key.Escape);
} catch {
// ...but don't try so hard that we fail if we can't
// simulate keypresses.
}
}
}
}
示例12: AutoBraceCompetionTest
private static void AutoBraceCompetionTest(VisualStudioApp app, Project project, string typedText, string expectedText) {
var item = project.ProjectItems.Item("Program.py");
var window = item.Open();
window.Activate();
Keyboard.Type(typedText);
var doc = app.GetDocument(item.Document.FullName);
string actual = null;
for (int i = 0; i < 100; i++) {
actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();
if (expectedText == actual) {
break;
}
System.Threading.Thread.Sleep(100);
}
Assert.AreEqual(expectedText, actual);
window.Document.Close(vsSaveChanges.vsSaveChangesNo);
}
示例13: AddReferenceAndBuild
public void AddReferenceAndBuild()
{
using (var app = new VisualStudioApp()) {
var project = app.OpenProject(@"TestData\ProjectReference.sln");
TargetInfo ti = TargetInfo.GetTargetInfo();
// Wait for solution to load...
for (int i = 0; i < 40 && app.Dte.Solution.Projects.Count == 0; i++) {
System.Threading.Thread.Sleep(250);
}
Assert.IsFalse(0 == app.Dte.Solution.Projects.Count);
// Set platform
foreach (SolutionConfiguration2 solConfiguration2 in app.Dte.Solution.SolutionBuild.SolutionConfigurations) {
if (String.Equals(solConfiguration2.PlatformName, ti.Plat, StringComparison.Ordinal)) {
solConfiguration2.Activate();
break;
}
}
// Build project
app.Dte.Solution.SolutionBuild.Build(true);
// Check for C# reference in the appxrecipe file
string appxRecipePath = string.Format("{0}\\TestData\\ProjectReference\\bin\\{1}\\Debug\\ProjectReference.build.appxrecipe",
Directory.GetCurrentDirectory(), ti.Plat);
Assert.AreEqual(true, File.Exists(appxRecipePath), string.Format("ProjectReference.build.appxrecipe is missing from bin output folder"));
string appxRecipeStr = File.ReadAllText(appxRecipePath);
Assert.IsTrue(appxRecipeStr.Contains("CSComponent"));
}
}
示例14: CloudProjectTest
private static void CloudProjectTest(string roleType, bool openServiceDefinition) {
Assert.IsTrue(roleType == "Web" || roleType == "Worker", "Invalid roleType: " + roleType);
using (var app = new VisualStudioApp())
using (FileUtils.Backup(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef"))) {
app.OpenProject("TestData\\CloudProject.sln", expectedProjects: 3);
var ccproj = app.Dte.Solution.Projects.Cast<EnvDTE.Project>().FirstOrDefault(p => p.Name == "CloudProject");
Assert.IsNotNull(ccproj);
if (openServiceDefinition) {
var wnd = ccproj.ProjectItems.Item("ServiceDefinition.csdef").Open();
wnd.Activate();
app.OnDispose(() => wnd.Close());
}
IVsHierarchy hier;
var sln = app.GetService<IVsSolution>(typeof(SVsSolution));
ErrorHandler.ThrowOnFailure(sln.GetProjectOfUniqueName(ccproj.FullName, out hier));
app.ServiceProvider.GetUIThread().Invoke(() =>
NodejsProject.UpdateServiceDefinition(
hier,
roleType,
roleType + "Role1",
new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)app.Dte)
)
);
var doc = new XmlDocument();
for (int retries = 5; retries > 0; --retries) {
try {
doc.Load(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef"));
break;
} catch (IOException ex) {
Console.WriteLine("Exception while reading ServiceDefinition.csdef.{0}{1}", Environment.NewLine, ex);
} catch (XmlException) {
var copyTo = TestData.GetPath(@"TestData\CloudProject\CloudProject\" + Path.GetRandomFileName());
File.Copy(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef"), copyTo);
Console.WriteLine("Copied file to " + copyTo);
throw;
}
Thread.Sleep(100);
}
var ns = new XmlNamespaceManager(doc.NameTable);
ns.AddNamespace("sd", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition");
doc.Save(Console.Out);
var nav = doc.CreateNavigator();
if (roleType == "Web") {
Assert.IsNotNull(nav.SelectSingleNode(
"/sd:ServiceDefinition/sd:WebRole[@name='WebRole1']/sd:Startup/sd:Task[@commandLine='setup_web.cmd > log.txt']",
ns
));
} else if (roleType == "Worker") {
Assert.IsNotNull(nav.SelectSingleNode(
"/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Startup/sd:Task[@commandLine='setup_worker.cmd > log.txt']",
ns
));
Assert.IsNotNull(nav.SelectSingleNode(
"/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Runtime/sd:EntryPoint/sd:ProgramEntryPoint[@commandLine='node.cmd .\\server.js']",
ns
));
}
}
}
示例15: ErrorListAndTaskListAreClearedWhenProjectWithMultipleFilesIsUnloaded
public void ErrorListAndTaskListAreClearedWhenProjectWithMultipleFilesIsUnloaded() {
using (var app = new VisualStudioApp()) {
var project = app.OpenProject(@"TestData\ErrorProjectMultipleFiles.sln");
app.WaitForTaskListItems(typeof(SVsErrorList), 14);
app.WaitForTaskListItems(typeof(SVsTaskList), 4);
var solutionService = app.GetService<IVsSolution>(typeof(SVsSolution));
Assert.IsNotNull(solutionService);
IVsHierarchy selectedHierarchy;
ErrorHandler.ThrowOnFailure(solutionService.GetProjectOfUniqueName(project.UniqueName, out selectedHierarchy));
Assert.IsNotNull(selectedHierarchy);
Console.WriteLine("Unloading project");
ErrorHandler.ThrowOnFailure(solutionService.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, selectedHierarchy, 0));
app.WaitForTaskListItems(typeof(SVsErrorList), 0);
app.WaitForTaskListItems(typeof(SVsTaskList), 0);
}
}