Programmatically manage references window in visual studio - c#

I created a VSIX package in order to find a list of methods implementations having a certain parameter type (using Roslyn and code analysis API). At this time I jump to a certain file location in solution. Using :
ws = componentModel.GetService<VisualStudioWorkspace>();
ws.TryGoToDefinition(mySymbol, myProject, cancelToken);
The thing is I have many symmbols I would like to display to user, using the same 'references' window that gets displayed when pressing Shift + F12 keys. Or a similar approach.
Has anyone got examples or link to code samples ?

Related

Library for Logging in Xamarin and error reporting style in MetroLog

I am an iOS developer which has been asked to do development in Xamarin. I want to log the outputs in Xamarin.
I am trying to find a library for this. I found one library for this called MetroLog.
Link : https://github.com/onovotny/MetroLog
But the problem is I am getting blue coloured output for every log level.Like this:
I was expecting that the errors would be in red , warnings would be in orange, and others in green or blue or something, but I could not get the required output in the manner I thought I would. I am running sample project from their repo , which has source code as follows:
_log.Info("Information - We are about to do magic!");
_log.Warn("Warning!");
_log.Trace("Trace some data.");
_log.Error("Something bad happened at {0}", DateTime.Now);
_log.Fatal("Danger Will Robinson!");
Are there some changes that I need to make to the logging project when it has been added to my project?
Is there any other library which can solve my use case for logging ?
If not then how can I achieve similar and coloured option from MetroLog ? I am open to other options(open source project) as well.
MORE INFO or EXTENDED QUESTION:
As I am used to iOS development I used to use the following statements in order to log the information:
NSLog(#"%# %# started" ,[self class] ,NSStringFromSelector(_cmd));
NSLog(#"%# %# ends " ,[self class] ,NSStringFromSelector(_cmd));
I am expecting some sort of quick logging option like the one for iOS as shown above without including any library. Is that possible?( including the class name and the method name which is executing the code)
Thanks.
I have not use MetroLog but, in general, such libraries requires you to set a destination / endpoint / server for your logs. The default one is often the basic one offered by the OS (which is the one that Xamarin Studio will redirect) and that won't give you coloured output.
Quick Logging: Every string given to System.Console.WriteLine ends up calling NSLog on iOS. Since that's part of mscorlib.dll (SDK) there's nothing else you'll need to add to your project to use it.

Programmatically assign hotkeys to VSPackage menu commands

I am developing a new version of a Visual Studio extension. In the old version, the hotkeys were stored in the registry and I would like to import these settings into the new version of the software.
The new version uses .vsct format for defining menu commands and you can assign the hotkeys in the .vsct file. However, I can't use this mechanism, as I would like to import the user settings from the registry, whiles the .vsct is a static description.
When my VSPackage is initialized, I can read the old hotkeys from the registry, but I have problems assigning them to my menu commands defined in the .vsct file. I can get a hold on the OleMenuCommand interface and OleMenuCommandService, but they have no property where they can accept key bindings.
How one can assign hotkeys to menu commands programmatically?
A clunky workaround would be that the installer imports the hotkeys, writes them into the .vsct file, compiles the file and puts the .cto into the MyPackage.Resources.dll during the installation. But I'd rather not resort to this...
Though I define my commands through the .vsct file, I still can access them via the EnvDTE.Command interface.
// The commandGuid has to be the same GUID you use in the .vsct file, HOWEVER, you have to include the braces here
Command command = dte.Commands.Item(commandGuid, commandId);
command.Bindings = new object[] { "Global::Ctrl+Alt+Shift+1" };
It works. It is saved and remembered the next time Visual Studio starts up, so there is no need to import the old hotkeys every time.
Since I'm not allowed to comment [despite my 50 years of systems-level programming experience, including 3 books for MS Press :( ], I have to ask this way for Shakaron to post some more of his code. I added a short tree of menu commands to the VS 2015 Tools menu (1-4-1 elements). An enumeration of dte.Commands didn't show any of them. Calling Commands.Item with a string (or an "object" to which I'd assigned a string) containing the GUID, both with and without {}, generated an invalid argument exception.
So, either the EnvDTE80 interface is incredibly fragile, the documentation is wildly wrong, or else Shakaron's solution has some more magic that we haven't seen yet. And I was so hopeful that this would be the last piece of my puzzle...
Answering Shakaron's questions:
I used the .vsct file to add 1 menu with 3 commands and 1 submenu, which in turn had 1 command.
Calling Commands.Item with a guid and an index argument caused an apparently identical invalid argument exception. I was able to enumerate the collection, but my commands were not in the set.
I also couldn't compile your code for the right-hand-side of the Bindings assignment. But, of course, I didn't get that far because I couldn't find the command item in the first place.
There has to be a version dependency at work here. I don't doubt that your code worked a year ago, but I ran into the problems I described using a fresh-out-of-the-virtual-box copy of VS 2015 running on Win 10.

get some parameter from user while installing a c# application

I have a C# win form application and I build a "setup" for it by visual studio 2010
my application needs some parameters like username , pass, ip and ...
i want to get these values from user before setup complete and save it to a file to use by my application. but how?
This answer presumes that you are using the Setup Project in Visual Studio. If you aren't edit your question and we can take another look.
To gather user input you need to introduce a new dialog to the installer.
The following steps will bring you to the part of the installer project that will allow you to add new dialogs:
In the Solution Explorer menu select the option "User Interface Editor"
In the newly opened screen right click on of the options (Install for example) and select "Add Dialog"
This displays a range of pre-built user dialogs. You will probably want one of the text box dialogs.
If you want something different you can also create a custom setup dialog. There is a nice code project post on doing this here.
Once you have this information you need to actually access it and use it during installation.
For this you need to add an installer class to your target project (the project you want to install).
In that installer class you can reference the text boxes you created using code like this:
public override void Install(System.Collections.IDictionary stateSaver)
{
string myPassedInValue=this.Context.Parameters["TEST"];
//Do what you want with that value - such as storing it as you wanted.
}
This answer is a little bit from 10000 feet - if I went into all the detail I'd end up writing a full article. If you have any sticking points, please ask. Also - have a look at this excellent article on the subject, it should get you most if not all of the way.
In VS solution explorer
Right click yoursetup >> View >> USerInterface
Right Click Start >> Add Dialog >> Select TextBox
Now made a Custom Class And add Install class file
Sample code
In Install.cs
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
string targetDirectory = Context.Parameters["Username"];
string servername = Context.Parameters["password"];
}

Debug mode works. Release mode generates ERRORs galore!

I have a solution that uses a native .DLL library that is wrapped by a .NET .DLL with a C# GUI.
All my plumbing works just fine in Debug mode. The moment I try going to Release mode, I get a whole whack of error messages, largely to do with the .CPP files in the native library. Errors include the following:
definition of dllimport function not allowed
TRACE_DEBUG_METHOD_CALL: identifier not found
a lot of undeclared identifiers in my main .CPP file (eg: DLLAPI_Release: undeclared identifier)
I have to admit that the Properties configuration for a C/C++ project is overwhelming so I wonder if there is one or more simple settings somewhere that I simply need to modify.
ALSO, is there a book out there that is devoted to the project properties window in VS2010 specifically? I have a few books but none really spend anytime on what is obviously a very crucial component to serious app development.
I appreciate any assistance anyone can offer. Thanks!
This is not unlikely to happen when you made a bunch of setting changes but didn't also make them for the Release build. Easy to forget, the first time anyway. You can easily tell which settings were changed from the default, they are displayed in bold type. Step through the setting pages, flip back-and-forth with the Configuration combobox in the upper left corner.
About 15 minutes of your life, not counting the thinking time you need because the setting should be different for the Release build. Start another instance of Visual Studio with a dummy project to verify that.
Trying to compare the property pages can be a beating. My recommendation would be to open the property pages for your project, select the Debug configuration, and under "C/C++", select "Command Line" and copy the command line options into a text editor, then do the same for the Release configuration and see where they differ. You'll need to do the same for the "Linker" command line.
Some of the differences will be intentional (e.g. debug flags should be set for the Debug configuration), but you should be able to spot things that should be the same but are not.
Actually tracking down where the command line options are set can be a bit of a pain, especially if you are using property sheets to manage common properties between projects, but generally you should be able to track them down just by looking through the different options on the different pages.
As for a reference, the best reference is the actual compiler documentation on MSDN. There is a section containing all of the documented compiler options and one containing all of the documented linker options.
The property pages are just a GUI frontend for setting these various options. When you select one of the properties in the property pages, it should say in the help box at the bottom of the dialog which compiler options are used by that property.

Releasing WinForm Program Updates

I'd like to release some updates for a WinForm program, but to date I have simply released an all-new compile. People have to un-install the old version and install the new version.
EDIT: I'm using an auto-generated InstalWizard. It preserves my file strucutre and places the [PrimaryProgramOutput] in a particular directory. I forget what this is called.
I bet there's a way to get around this, but I don't know what it's called. As you may guess, searches for "updates" "new version" "install" and the other obvious things I've tried have generated an impressive number of irrelevant results. >_<
I suspect this process has a particular name, which should point me in the right direction, but if it doesn't please link to a tutorial or something.
I see from the tags you are using C#. Visual Studio can create Setup projects for these kind of tasks. The setup projects als contain a property RemovePreviousVersion, which will remove a previous version if the versioning of your setup is correct and the GUID of the application stays the same.
See this link for more information:
http://www.simple-talk.com/dotnet/visual-studio/updates-to-setup-projects/
ClickOnce deployment is a great solution most of the time...
You can deploy to the web and when ever your users start the application it will check for updates and automatically update the application if there is a new version available.
It can also be configured not to update automatically but only to notify the user that there is a new version available and allow the user to control the update process.

Categories