List of open documents in VisualStudio (Plugin-Development) - c#

I am currently trying to develop a simple plugin for visual studio 2008 using c#.
I feel kind of stupid to ask, but after searching the doc for a few hours I can't find a way for a really simple task: Assume this open solution. I simply want a list of the documents open in the TABs on the right. I tried something, see below...
alt text http://img24.imageshack.us/img24/5238/20091201172237.png
This approach is not working:
alt text http://img339.imageshack.us/img339/6571/20091201172211.png
And the result is rather strange:
alt text http://img40.imageshack.us/img40/6535/20091201172247.png
Any tips on how to list the active documents?
Thanks,
Chris

Can't answer your specific question, but can make a couple of comments/suggestions:
The DTE object model is ugly, ugly, ugly - you're not the only person who's struggled with it (ask me how I know).
Ask your question on the Visual Studio Extensibility Forum - they can probably help.

Ok,
I just found a way around the ugly DTE. Its simply not using it :-) At least not directly. I found DxCore, which is free (at least for personal use, I guess) and does the job quite nicely.
To get what I wanted, I simply needed this code (which was what I was hoping in VS for, but there it kind of behave different)...
alt text http://img109.imageshack.us/img109/7127/20091201221414.png

Related

How do I find which nested namespace to import in C# for the classes I need in my code?

This is one of the things I find infuriating about C#. I have thsi massive library im trying to use right now and for some reason the people who create the code examples are not smart enough to include the namespaces you need to import in the examples. This is usualyl the case. I find myself searching through the namespace, hundreds sometimes nested trying to figure out which ones i need to import. In java netbeans, it even tells me which packages to import because it searches for me. But in C# i always waste countless time searching through the namespace manually.
Is there any way I can get around this. Like right now im trying to find which namespace contains TwitterCredentials for Tweetinvi library.
Seriously, why do people not include the namespace in code examples. It's just stupid not to!
And why does visual studio not make suggestions like java. It's just common sense really....
You can press Ctrl + . on each word that has error or point to small blue bar under the word and click on dropdown, and use offered namespace.
I am the developer of Tweetinvi :)
ALL the classes you need in Tweetinvi are located in the Tweetinvi.Core.* namespace.
TwitterCredentials.cs
To answer your question regarding Namespaces and why I do not include them in the examples. The reason is that as mentioned by Reza Aghaei Visual Studio and Resharper allow developers to include namespaces.
Furthermore as you mentioned the library is big and therefore multiple namespaces might be required and I am not going to add all of them in each example. Otherwise the documentation would just be huge.
I hope you will like the library and please feel free to ask any question here on stackoverflow or on github.
Happy coding.
PS: By the way you can also use Github to search for filename with a 't' keystroke on the Source Code page.

How to programmatically create custom comment tokens

I am writing a small Visual Studio addin to let the user use more features of the comment tokens (TODO, HACK, etc.). For this I want to extend Visual Studio with new commands (such as TODISCUSS, TODELETE, FIXME, TESTME, etc.). I'd like to do this programmatically when my addin starts.
I already found out how to do this manually: http://msdn.microsoft.com/en-us/library/ekwz6akh%28v=vs.80%29.aspx
Does anyone have an idea how this could be done via the API?
Any ideas or suggestions would be appreciated!
Edit :
See this MSDN Link perhaps digging around in TaskList will get you somewhere.
Original Post :
It's not very clear (to me :) what exactly you want to do. Is it: find, edit, or refactor the tokens and then do something else with the sources? I can suggest this article on Code Project (NRefactory).
Using NRefactory you can do anything and everything with the source files including locating the tokens you want and doing stuff with them. You will also know the files you found them in, line numbers etc.
Perhaps you will be able to use Nrefactory to do all the heavy lifting as far as sources are concerned.

printing every page of a VSTO project

I'm using visual studio and I'd like to have a paper copy of my project. There are c# libraries, aspx files, javascript files, css... I'd like to print everything at once to my pdf printer. I know I can do this one file at a time but I was wondering if there is a magic button for that?
Thanks.
Having just looked for the same thing a couple weeks ago, there isn't a perfect solution that I could find... This question was asked before:
Visual Studio: Printing all source files in a solution?
With the answer pointing to an old macro from MSDN here:
http://msdn.microsoft.com/en-us/library/ms973240.aspx
Another search turned up a result for a commercial product that claims to do what you're looking for, however, I haven't tried it and was unable to even find pricing:
http://submain.com/products/prettycode.print.net.aspx
Hope that helps, in the end I just opened all the files at once and just closed each one as I printed it. Not at all ideal, but it got the job done at the time.

C# Rich Text Box, Brace Matching

Is there a good open source project with brace matching support? I was searching codeproject all day but failed to find any. Or atleast can someone advice me on how to tackle it? Thanks!
It can be in C# or VB.NET.
Edit:
Sorry forgot to mention, I do not want to use other dll components since I'll have to include them in the directory to use them... I'd create my own so all I have is JUST the exe file to give out. Thanks!
Not sure if these provide what you need, but worth a look:
scintillanet is a C# wrapper around the scintilla control
ICSharpCode.TextEditor from the SharpDevelop project

Windows.Form c# without visual studio

I am trying to learn Windows.Forms, and while I have Visual Studio (edit, my mistake obviously), I feel that I learn much more effectively by doing everything in Notepad. I have searched everywhere for a tutorial that takes this approach. I finally got started with http://www.geekpedia.com/tutorial33_Windows-forms-programming.html, but after the first example, it too begins working with multiple files? somehow generated with Visual Studio. How can I do this in Notepad? Can anyone point me somewhere helpful?
Thanks!
**While the overwhelming response seems seems strongly against this and I started to be convinced, I saw SmokingRope talking about it being as simple as writing all classes into one file. This is what I have been doing up till now for sizable, just non Windows.Form projects into. Can you maybe help explain how those necessary files can be included using this method?*
Seriously... I admire your fire, but you are out of your mind! What you can possibly hope to learn about .NET with NotePad that you couldn't learn a zillion times faster with Visual Studio? It's like asking, "I want to learn to drive a car. I have put wheels on my couch. What should I do next?"
I mean no disrespect, but make friends with Visual Studio and get busy learning. You're wasting your time otherwise.
It is actually quite easy to code C# outside of the IDE. It will basically come down to using the csc.exe compiler from the command line prompt.
The hardest part of this process is making sure the environment variables are correctly configure and Microsoft provides the vsvars32.bat batch file to do exactly that.
Here is a short tutorial on how to do use this batch file and the compiler from the command line: http://www.zeusedit.com/forum/viewtopic.php?t=1235
And an even better, but slightly more complicate approach is to use MsBuild utility to manage the building of the project: http://www.zeusedit.com/forum/viewtopic.php?t=2518
Finally you can even use the external C# Debugger to debug you programs: http://www.zeusedit.com/forum/viewtopic.php?t=2507
Your best approach is really to learn how to write code from within Visual Studio. You gain a lot of coding assistance (IntelliSense, syntax checking, etc.) that will help you learn the language.
If you really want to use Notepad, then you create as few or as many files as you want and then compile them in to an assembly using the command line compiler by listing each file as an input to the compiler.
The reality of this is that using notepad and the command line compiler is possible but very cumbersome and almost never used outside of showing simple "Hello, world" type examples.
I am going against the grain here... But I think that your idea is not such a bad one... especially for a small project.
But using Notepad (or at LEAST use Notepad++) will teach you more about MSBuild and the VBC or CSC compiler syntax than it will teach you about the language features. The best way to learn the language, is, as other have said, using Visual Studio. The intellisense is a great way to learn.
But it also makes us lazy and it is true that we don't have to memorize as much...and sometimes having things memorized comes in handy. (ie.... I am at a customer and logged in remotely to the servers... no visual studio is installed... BUT... yippee... .NET 2 is there... at that moment you will have appreciated the exercise...)
Honestly, to do this for a reasonably small project I think would be a good exercise in learning. I say go for it. Hell, I might even join you.
But, that said, I think the very best way to do it would be to use both methods side-by-side. For example... If you want to use multiple files the way to do that is to create a folder and put an vbproj (or csproj) file in it. MSBuild.exe receives vbproj files (and sln files for that matter) as arguments. So, one of the quickest ways to learn the vbproj file syntax is to use visual studio to create a project... and then open the vbproj file in Notepad++.
The problem is that Visual Studio IS SO AWESOME BECAUSE it abstracts so much away from the developer. But it is silly to not acknowledge there is a downside to that. That abstraction means that we don't need to have as deep an understanding. Things just work automagically. So I say dig a little deeper. I don't think you will regret it.
Assuming that the thing you want to avoid is magically-generated-code and visual designers, you can just open the System.Windows.Forms namespace and start coding against the APIs. Start with that first example, and then programmatically add buttons and textboxes and whatnot. You don't have to create a forms project or work with the designers, you can just 'write code' in VS and turn off all the magic.
If you're looking for example code, you might consider looking at F# samples, e.g. the UI stuff at
http://code.msdn.microsoft.com/fsharpsamples
for ideas of a few basic controls you can add to forms to do basic UI stuff.
You can write multiple classes in a single C# file (despite the generally accepted best-practice of putting one class per file):
using System;
namespace Test{
class Class1{ }
class Class2{ }
}
You also could look into how the MSBuild system works from the commandline. I believe you will still have to maintain a project file (xml type syntax, use visual studio to create a project and then open that in notepad for an example) but i don't have any experience with it personally.
It's possible to do it all from notepad and the command prompt. You will probably find it to be a little more time consuming however.
If you want to learn c# and winforms, part of the skill set you need is being proficient in Visual Studio.
You can do things in Notepad for awhile (I wrote some web services in notepad once because I didn't have VS available), but eventually you will want to take advantage of the tools available in VS.
I highly recommend you use Visual Studio (Microsoft offers free Express versions that will meet your needs). Learning the syntax of the language is wonderful, but you must be able to work within the VS environment to be truly successful in C# (and any of the .NET languages). It benefits you more to do it right and learn it all together rather than try and piece it together later. Just my own two cents.
Just to repeat what's already said, again with no disrespect, you are not going to learn .NET in notepad. It's just not probable. Not only are you not be productive, but you're also not going to learn the tools used in the industry, best practices, and other important factors about .NET. It's not just about sitting down and writing code. By limiting yourself to notepad, it's like limiting yourself to one meal a month: you lack the nutrition needed to keep moving forward at a good pace.
Utilize the tools and resources available to you. Limiting yourself like that is a kick in the rear end.
Use sharpdevelop (Windows) or monodevelop (*nix). Both have Windows.Form support. Although they dont offer as much as VS, they'll at least get you started. I've never used the VS Express edition, so I don't know what it's limitations are.
Note that notepad is not even the equal of vi not to speak of vim.
If you want to use a text editor then you could try it but I don't see the point of using notepad. Use a real text editor, not necessarily vim/emacs, you could pick a nice gui text editor like notepad++ or kate.
Notepad can't even display unix line endings(I think).
Go download an Express edition of Visual Studio. I understand the possibility of thoroughly learning this via notepad, but with a free IDE out there, it makes no sense.
if u have something against MS or VS.net u can try sharpdevelop
http://www.icsharpcode.net/OpenSource/SD/
last time i looked it was xcopy deployable :)
I don't know where to find tutorials, but the approach is pretty straightforward: import System.Windows.Forms, derive a class from Form, and give it a .Show(). Your components are members of the class, and can be positioned using their respective position/size properties. Events are handled through delegates.
I do see where this technique is useful, though I'd use a decent IDE instead of Notepad. .NET is just too prolific. Knowing how to construct forms on the fly can come in handy.
If you're looking for an alternate IDE, check out icSharpCode's SharpDevelop.
Also, look into JScript.NET tutorials - there is no forms editor for that language, as inheritance simply isn't possible. But it's still based on .NET, so the basic motions are the same. Here's a decent one:
http://www.webreference.com/js/column117/
I know this is answered by strangely I haven't seen anyone talk about NAnt.
For years I developed in TextPad, with some syntax highlighting, + NAnt to do my builds. These days it'd be even easier as you can have your buildserver prep a proper msbuild for you (CC.NET + NAnt).
I also learned about a few things that physically couldn't do in Visual Studio (at the time it was .net 1.1). Definitely a good experience, and I'd recommend it really. Probably not for winforms though, because the designer is actually useful for that.
i am a notepad user. :) i don't have visual studio installed on my computer.
this is what im doing.
1st u must register your .net framework folder on Environmen Variables.. Path
or run on CMD this lines
path=%path%;(this is where ur .net framework address were)
(ex path=%path%;C:\Windows\Microsoft.NET\Framework\v4.0.30319)
then hit enter
2nd to compile a single notepad(save as .cs), locate the destination of the file using cmd. then. type "csc nameOfCS.cs"
for multi file.. "csc ManinCsForname.cs classes.cs classes.cs"
it will compile as exe.
for more command.
"csc /?"
its ok to use Visual Studio. but if you want to become more familiar with C# and structure. or can make a system on any PC. without using any IDE. u can do this.
Not using Notepad will help. Crimson Editor or TextPad or others have line numbering, syntax highlighting and many features you'd need. I'm sure Notepad has file size limitations which you might run into.
The sans-IDE element I can only fully answer from a Java point of view. I've done a fair amount of Java UI development using Crimson Editor, the Java SDK, batch files and/or either ANT or Maven at times. If you developing UI code that's generic or does a fair amount in dynamically then its ok. If your work involves designing many different specific Forms (i.e. screens that have many customer forms and aren't subject too much reuse) then the Designer features of the IDE are extremely useful.
However, I have found .NET IDE development a little frustrating coming from the above model of Java development.

Categories