Is it possible to programmatically set trace points in VS 2010? - visual-studio-2010

This is in reference to the Visual Studio automation interface. It is possible to set breakpoints in a program using the method:
EnvDTE.Debugger.Breakpoints.Add(...)
However, I don't think it's possible to configure trace points this way. Any ideas?

Check out the answers in this post particularly the BreakWhenHit = false, Message, and Macro properties of the Breakpoint2 interface.

Or you could also look at a logging framework like Log4Net.

Related

What visualizer is currently used

On the internet (Microsoft website, e.g.), there's plenty of information on how to create a visualizer.
However, I'd just like to know, which visualizer is currently used by my debugger?
For Native code, that question is very simple:
Menu "Tools", "Options", "Debugging", "Output window", "General Output Settings", "Natvis diagnostic messages", set to "Verbose".
In the Watch-window, enter .natvisreload
Verify the "output" window: all native visualisers are mentioned.
However, now I'm working with managed code, and in my watch-window, I see entries like:
{User Info: 12 User(s), 6 Group(s)
{VDX File Change Info (117 files)}
…
Those entries give me the impression that for this managed code, a/some visualiser(s) is/are used, and I'd like to customise, expand or modify it/them, but therefore I need to know where it/they is/are (sorry for the bad sentence, I just want to emphasize that I have no clue of the whereabouts of the visualiser(s)).
How can I know which managed visualizers are used in my Visual Studio session?
Thanks in advance
Dominique
You'd have to integrate with the debugger and see what types are being evaluated in the watch/autos/locals windows.
From there you can find those types in the list of modules loaded (using debugger apis) and then search for the attributes that Leo mentioned.
There's no debug output anywhere about which type visualizers are loading for managed code. It's actually stored on the types themselves.
How can I know which managed visualizers are used in my Visual Studio session?
According to the document Create custom views of managed objects:
In C# and Visual Basic, you can add expansions for custom data using DebuggerTypeProxyAttribute, DebuggerDisplayAttribute, and DebuggerBrowsableAttribute.
In .NET Framework 2.0 code, Visual Basic does not support the DebuggerBrowsable attribute. This limitation is removed in more recent versions of the .NET Framework.
DebuggerTypeProxy Attribute
DebuggerDisplay Attribute
Hope this helps.

How to compile Shadows events using MSBuild

I am trying to use set up a CI server that doesn't depend on a Visual Studio installation but uses msbuild instead. Our solution includes an interop project. Visual Studio handles this project just fine, but msbuild seems to have a problem with events like this one, taken from an interop user control which inherits from System.Windows.Forms.UserControl:
Public Shadows Event Click() 'Event must be marked as Shadows since .NET UserControls have the same name.
The error I get from MSBuild is this:
error BC30029: Derived classes cannot raise base class events.
I read this, but my Event statement and RaiseEvent statements are already in the same class (the one from which the above error is being thrown). I don't think this solution applies to my situation.
What's the best way to get around this? Let me know if you need more information.
Thanks.

Is there a tool for Visual Studio which can show the list of all called functions?

When debug application, it may be usefull to see in what sequence methods are called. It is possible to write Debug.WriteLine("Called MethodName") in earch method but there are big number of methods in my project.
Is there tool that logging method calls?
Runtime Flow (developed by me) shows all function calls in a .NET application.
As mentioned in a comment, the Visual Studio Call Stack window already implements this.
However, if you really wanted more information you can always look in to adding Tracing information.
You could use an AOP (aspect oriented programming) framework to make your life a bit easier.
There is a worked example of how to use PostSharp to log method calls here: http://www.codeproject.com/Articles/337564/Aspect-Oriented-Programming-Using-Csharp-and-PostS

Create Language Service for VisualStudio 2010

I want to build a language service for visual studio 2010. I was first trying to follow the tutorial and documentations from MSDN.
The problem is i don't succeed to make this works (i'll explain later my problem). So i digged into existing implementations, i found Ook! and lua . both of these projects doesn't use the tutorial or documentation i found on MSDN, but something based on MEF. Lua used this only with previous Visual Studio versions.
So i'm wondering if i'm using an obsolete method to create a language service (But the documentation aims Visual Studio 2010), or there is different ways to do this, which depends on needs.
In my case, i've got a language that doesn't need to be compiled into cli, but i want to have an editor that have colorization, syntax warnings and errors, intellisense ...
The problem i mentionned is that when launching exp instance, there is no text editor with my file extension, and visual studio begins to have many lags. The language service is registered using 3 attributes : ProvideServiceAttribute, ProvideLanguageServiceAttribute and ProvideLanguageServiceExtension. Also initialized in Package intialize method, like mentionned in Proffer the Language.... The package is loaded when i try to open the file with my extension, the language service is initialized.
So i don't get it why i does not work, could you please help me to understand how language service works, and what is the best way to implement it
Thanks
Good chance your IScanner implementation has an endless loop, happened to me.

Visual Studio - How to remove a reference in Release mode

I'm developing a library for use in other apps and this library has lots of debugging and logging statements thanks to NLog.
Is it possible to exclude the reference to NLog.dll when I switch to release mode?
Cheers,
You can manually edit the csproj file, and do something like this:
<Reference Include="NLog" Condition="'$(Configuration)' == 'Debug'" />
This only makes it reference that assembly in Debug. I wouldn't recommend doing this often though, because this behavior isn't reflected in the references list in Visual Studio when you change the configuration. It does work when compiling though
The only way I know is to take the reference out completely and call the assembly via reflection. Then, you should only log if the assembly loads.
I can't think of a good way to do this. Unless maybe you wrote a stub reference for NLog.dll. Since you are using the reference in your code I don't see how you could just remove it in your release.
Probably too late now but in the future you could write a class to wrap NLog.dll and then just change it in one place so it wouldn't actually log in the release version. Or have some sort of flag.
There is no reason for removing a reference in case you are sure that no code will be in use from that DLL. In that case you can simply remove DLL.
Why would you want to do that?
If you want to stop logging, you can programatically turn off the logging. The performance hit will be minimal. (I have had great success with NLog even when logging cross process.)
Otherwise, you need to wrap it as described above.
-Scott

Resources