Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

VS Macro for deleting line numbers

When you copy code from internet and paste into Visual Studio, have you ever faced the trivial task to remove line numbers in the front of each line of code? I just wrote a macro to do this and I’d like to share it with you.

When we past code into Visual Studio, it often looks like this:

MacroForRemovingLinenumber

With this macro, we can remove line numbers very quickly. And the following is the script code. It will set the cursor to the start of current opened document, parse the first 3 characters of each line until the end of the document.

    Sub DeleteLineNumber()
Dim objSel As TextSelection = DTE.ActiveDocument.Selection

objSel.EndOfDocument()
Dim endLine As Integer = objSel.ActivePoint.Line
objSel.StartOfDocument()

For line = 1 To endLine

For bit = 1 To 3
objSel.CharRight(True)
Dim number As Integer
If Integer.TryParse(objSel.Text, number) Then
objSel.DeleteLeft()
End If
Next

objSel.LineDown()
objSel.StartOfLine()
Next

End Sub


To use this macro, you can




  1. Launch Visual Studio


  2. Press ALT+F8 to open Macro Explorer


  3. Expand MyMacros node in Macro Explorer


  4. Right click a module and select ‘New macro’ to create a new macro.


  5. Past in the script.



And there are several ways to run a macro. They are described in How to: Run Macros. If you find any issue or has any comment, please feel free to let me know

Correct way of applying Visual Studio 2008 SP1

Visual Studio family contains many products. The VS 2008 SP1 released a few months ago have fixes for all products in the family. An incorrect order of applying the service pack usually lead VS products into an inconsistent state. The most common issue I see is that a particular method/type in a VS assembly can't be found.

In Visual Studio 2008 SP1, we have fixes for

  1. Visual Studio IDE.
  2. Team Explorer.
  3. Load Test Controller.
  4. Load Test Agent.

See KB 950264 for detailed description.

When applying the SP1, only fixes for already installed products are applied. For example, you might have installed Visual Studio 2008, then applied the SP1, latter you installed the load test controller on the same machine, then fixes for the test controller would not be applied unless you install the SP1 again.

So, the correct order of applying the SP1 is to install the SP1 at the latest. If you applied the SP1 and later installed a new product in the above list, then you should apply the SP1 again.

Useful commands for solving Visual Studio problems

Visual Studio(VS) is a very complex software. Sometimes you may suffer issues while using it. Here are some commands that might help to bring VS back to normal. If you have multiple version of VS installed, make sure the commands are run in the installation folder of the correct version of Visual Studio.

  1. devenv /ResetUserData
    This command is used to reset user data. Settings in the Tools->Options within Visual Studio will be reset. You might need to export your settings before run this command.
    In MSDN forums, I saw many customers reported that VS is in weird states such as a window is missing, tool buttons in a window is not correct etc. This command solved most of these issues.
  2. devenv /ResetSkipPkgs
    When a package loading error occurs, we may suppress VS to load it in the future. This approach hides the problem. ResetSkipPkgs switch will make VS to load the skipped packages while launching VS. After we get the error message for package loading error, we can do more troubleshooting.
  3. devenv /setup
    This command is used to build menus, commands and registry settings for all VS packages. Many VS add-ons contain packages. When we get package errors for an add-on, the first thing to try is repairing the add-on. If the repair doesn't work, just run devenv /setup.
  4. devenv /SafeMode
    This command will start VS in safe mode. In safe mode, VS will not load any third party packages.