August 2012 - Posts

One of the very nice things about Visual Studio is that all of the tools you need are in one place. With one integrated development environment, you can build your database, create your resource strings, write your code, write and run unit tests, check into source control, and so on. And if you find another tool you like, you can add it easily to Visual Studio's Tools menu to keep everything in one place.

Let's walk through an example. Say we want to add the Convert.exe from this prior blog post to the Visual Studio menu.

1. Select Tools | External Tools.

The  External Tools dialog opens.

image

This is not the most user-friendly of dialogs. It takes a moment to figure out what you need to do here.

2. Click  the Add button.

This clears the bottom section in preparation for adding a new menu option to the Tools menu.

3. Enter the Title, executable, any needed arguments, and if desired, an initial directory.

image

4. Click OK

The defined tool is now on the Visual Studio Tools menu.

image

[The red box around the new menu option was added for clarity and won't appear in Visual Studio.]

Use this technique any time you want to add your own tools to Visual Studio.

Enjoy!

with 2 comment(s)
Filed under: , , ,

As .NET developers, we sometimes need to convert code from C# to VB or from VB to C#. Bing may have returned the perfect example of what you need, but it is in VB and you need C# code. Or some sample code you downloaded is in C# and you need it in VB. Whatever the case, Visual Studio 2012 now provides a tool for converting code between languages.

The Convert .NET tool is available from the Extensions and Updates (which were introduced in this prior blog post). Select Tools | Extensions and Updates. Then search for Convert .NET. Click Download to download and install it.

image

Instead of installing, however, the download option displays the Convert .NET Web site. After hunting around for a while, I found that clicking on the Version number at the bottom of the page next to a small download icon, downloaded the tool as a .zip file. You can then unzip it to run the executable.

When you launch the executable, the first drop down list allows you to select the type of conversion. Select C# <-> VB.NET Converter. In the second drop down list, select whether to go from C# to VB.NET  or from VB.NET to C#.

Paste desired code in the top window and click Execute from the toolbar. The converted code then appears in the bottom window.

image

Note, however, that the conversion is often not perfect. For example, if you can read the above conversion, you'll notice that the first Dim statement that it generated in the VB code is not valid. So you may need to tune the converted code.

Use this tool as a starting point any time you need to convert code from C# to/from VB.NET.

Enjoy!

with 7 comment(s)
Filed under: , , ,

"Extensions and Updates" is the new name for the Visual Studio 2010 "Extension Manager". With it you can find samples, tools, and Visual Studio extensions.

To access it, select Tools | Extensions and Updates from the Visual Studio 2012 menu.

image

Click Online on the left, then Visual Studio Gallery to view available tools and Visual Studio extensions. Select Sample Gallery to view downloadable samples.

Use the Search box in the upper right to filter and the Sort by to sort the results.

Use this feature any time you are looking for additional tools, such as a spell checker or refactoring library. Or looking for new templates such as Entity Framework (EF) or MVC templates.

Enjoy!

with 1 comment(s)
Filed under: , ,

There has been minor controversy over the use of upper case letters in Visual Studio 2012's menus. No need for concern. If you really hate them you can turn them off!

image

(Upper case characters are sometimes considered to be shouting.)

There are three ways to change your menus to proper case:

1) Registry Key

a) Open a registry editing tool such as RegEx.exe.

b) Navigate to the following node:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General

c) Right-click on the node and select New | Dword value.

d) Set the name to SuppressUppercaseConversion.

e) Set the value to 1.

2) NuGet Package: VS2012_RemoveAllCaps

a) Open a solution in Visual Studio.

b) Select Tools | Library Package Manager | Manage NuGet Packages for Solution …

c) The Manage NuGet Packages dialog opens.

d) Select the Online tab and type RemoveAllCaps in the search box found in the upper right corner of the dialog.

e) Click the Install button next to the found package.

image

3) Visual Studio Extension: VS Commands 2012

a) Open Visual Studio.

b) Select Tools | Extensions and Updates.

c) The Extensions and Updates dialog opens.

d) Select the Online tab and type vscommands in the search box found in the upper right corner.

e) Click the Download button to install the extension.

image

f) After the installation of the extension, select Tools | VSCommands | Options. Select Main Menu from the left and adjust the letter case:

image

The result:

image

Enjoy!

Thanks to the language MVPs for sharing these techniques.
with 3 comment(s)
Filed under: , ,

You would think that giving an application a title and later retrieving that title would be a straightforward thing to do in VB.NET or C#. But it turns out to be a little complex, especially to find the appropriate place to enter the title then to write the appropriate code to retrieve that title.

First, enter the title of the application.

In C#:

  1. Find the project in Solution Explorer.
  2. Double-click on the Properties node under the project in Solution Explorer.
  3. Select the Application tab.
  4. Click the Assembly Information button.
  5. Enter the desired title into the provided dialog.

image

In VB:

  1. Find the project in Solution Explorer.
  2. Double-click on the My Project node under the project in Solution Explorer.
  3. Select the Application tab.
  4. Click the Assembly Information button.
  5. Enter the desired title into the provided dialog.

image

Second, write the code to retrieve that title. In this example, the title is provided as an ApplicationName property.

In C#:

/// <summary>
/// Gets the name of the application.
/// </summary>
/// <value></value>
/// <remarks></remarks>
public static string ApplicationName
{
    get
    {
        var entryAssembly = Assembly.GetEntryAssembly();
        var applicationTitle = ((AssemblyTitleAttribute)entryAssembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0]).Title;
        if (string.IsNullOrWhiteSpace(applicationTitle))
        {
            applicationTitle = entryAssembly.GetName().Name;
        }
        return applicationTitle;
    }
}

In VB:

''' <summary>
''' Gets the name of the application.
''' </summary>
''' <value></value>
''' <remarks></remarks>
Public Shared ReadOnly Property ApplicationName() As String
    Get
        Dim applicationTitle = My.Application.Info.Title
        If String.IsNullOrWhiteSpace(My.Application.Info.Title) Then
            applicationTitle = My.Application.Info.AssemblyName
        End If
        Return applicationTitle
    End Get
End Property

The C# code defines a static property for the application name. Its getter first determines the entry assembly, which is the first executable that was executed. So even if this property is in a library component, if the application was launched with a WinForms or other UI component, the entry assembly is the UI component and not the library. If the code needs the currently executing assembly, replace GetEntryAssembly with GetExecutingAssembly.

The C# code then uses GetCustomAttributes to obtain the AssemblyTitleAttribute from the assembly to then retrieve the title.

If for some reason the title attribute was not set, the code uses the GetName method to retrieve the name of the entry assembly and uses the retrieved name.

The VB code uses the My namespace to retrieve the application title. The My namespace provides a very nice shortcut to the application's title attribute. If for some reason the title attribute was not set, the code uses the AssemblyName, also provided within the My namespace.

In both languages, the application title is "Acme Customer Management" as defined in the Assembly Information dialog.

Use this technique any time you want to define the application title in the assembly information and retrieve it for display or logging.

Enjoy!

with no comments
Filed under: , , ,

Someone asked me about this, and though ampersands in menus is as old as VB 1.0 the question comes up because the associated shortcut keys don't appear underlined by default in some versions of Windows.

Most Windows Forms applications have a menu bar at the top. The menu in my sample application looks like this:

image

The original Windows Forms layout standards suggested that each primary menu and menu option have an associated shortcut key. That way the user can access the menu options without having to move their hands from the keyboard.

In Visual Studio, you define the shortcut key for a menu or menu option by adding an ampersand (&) in front of the character in the menu option Text property. For example, the Text property of the Help menu above is defined as "&Help". This identifies the H as the keyboard shortcut key. The About menu option is defined as "&About", making the A the shortcut key.

With Windows 7 (and Vista I believe), you don't see the keyboard shortcut  key shown underlined in the menu by default. You have to press the Alt key for underlines to appear. In my example, only the Help menu and menu options have short cut keys.

image

As you hold down the Alt key, you can press H to open the Help menu, then A to open the About box.

Enjoy!

with no comments
Filed under: , ,

One of the many new Visual Studio 2012 features is the Quick Launch bar. With it, you can perform a feature keyword search. The Quick Launch bar provides a list of matches. When you pick one of the matches, Visual Studio launches the associated feature.

image

For example, say you want to turn line numbering on. You can type "line" in the Quick Launch bar:

image

Hover over the items to read the (sometimes long) tooltips, you can glean that the option that you need is the second one from the top. Picking it launches the Tools | Options dialog:

image

You can then turn line numbers on or off.

As another example, type "Toolbox" to quickly find the option to open the Toolbox window:

image

Selecting the first entry opens the Toolbox.

Enjoy!

with 1 comment(s)
Filed under: , ,

In this prior post, I introduced the new VS 2010 Database Project. Forget all of it. VS 2012 comes with a new Database Project!

I have not yet worked with the new Visual Studio 2012 Database Project, but will write a post as soon as I do.

For now, I wanted to provide your choices if you want your solution to work in both VS 2010 and VS 2012:

  • You can choose to not upgrade the Database Project when first opening the project in VS 2012.

image

OK, I had to read the first sentence of this dialog box a few times before I understood what it was trying to tell me. Some hyphens may have helped to make it more clear: "These projects are either not supported or need project-behavior-impacting modifications to open in this version of Visual Studio."

This basically means that the projects listed are either not supported in or not compatible with Visual Studio 2012 without making some changes.

To prevent Visual Studio from upgrading the projects for use in Visual  Studio  2012, just uncheck the checkbox and click OK.

NOTE: Even though this dialog says you will be able to open an upgraded Database Projects in Visual Studio 2010 SP1, you can't. Not unless you install an additional set of tools. More on this under the next bullet point below.

  • You can choose to upgrade the Database Project and then add the tools required for your Visual Studio 2010 to read the new Visual Studio 2012 Database projects.

To allow Visual Studio 2012 to upgrade the Database project, leave the project checked in the dialog shown above and click OK.

The Migration Report will notify you of the changes that Visual Studio made to your solution. It  also provides details on the tool you need to install in order to open the Visual Studio 2012 Database Project in Visual Studio 2010.

image

If you attempt to open a solution containing a Visual Studio 2012 Database Project in Visual Studio 2010, you will see the following dialog.

image

Use this link to download the SQL Server Data Tools for Visual Studio 2010. These tools will allow you to open the Visual Studio 2012 Database project in Visual Studio 2010. If you are working on the solution with other team members that are using Visual Studio 2010, they will also need to install these tools.

I didn't want to interfere with any of the other members of my team, which were all using VS 2010, so I opted for the first choice: not upgrading the Database Project. What you decide depends on your situation and your team.

Enjoy!

with no comments
Filed under: , , ,

Had a GREAT time at Visual Studio Live in Redmond earlier this month.

If you are looking for the sample code from my talks, you can find it here.

Have feedback or questions from the talks? Feel free to post them in the comments below.

Enjoy!

with no comments
Filed under: , , ,

For the first time in Visual Studio history, you can open a Visual Studio 2010 project with Visual Studio 2012, save it, and open it again in Visual Studio 2010. They are backwards compatible!

If you want to use the new features of the Visual Studio 2012 editor on your current solution before the other members of your team, you can. You can open it and edit it in VS 2012 and they can open it and edit it in VS 2010.

I started using VS 2012 back in February 2012, even through the rest of my team were using VS 2010.  I was able to check in/out from TFS without impacting the other members of the team using VS 2010.

The only issues I ran into were:

  • The Visual Studio 2010 Database project is not compatible with VS 2012. But VS 2012 lets you decide to NOT upgrade it. It then looks like the screen shot below.

image

  • Office 2007 projects are not compatible with VS 2012. They won't open and appear similar to the database projects.

I often have VS 2010 and VS 2012 open at the same time, editing in one and in the other. I can edit my Database project scripts and our Office 2007 project in VS 2010 and then edit the rest of my projects in VS 2012. (Similar to the experience with editing in Visual Studio and Expression Blend at the same time.)

Enjoy!

with 4 comment(s)
Filed under: , ,

The news about the orphaning of Silverlight hit me like a rock. I dove head first into Silverlight/MVVM a few years ago and had begun to feel like I could bend it to my will. I was disappointed, unhappy, and just sad about this news.

Pair that with a very bad case of "empty nest" syndrome (I really miss my daughters!), and I was too low to get excited about creating a blog post.

A few weeks ago, I began to feel the weight of this depression ease. After having some fun with a preview of VS 2012, a European trip with my immediate family, a week in Wisconsin with my extended family, and a long week-end at Comic-Con with my oldest daughter, I was starting to feel normal again. (See the Comic-Con pictures here.)

I'm glad to be back here, in the blog-sphere.

with 4 comment(s)
Filed under: