Tuesday, August 4, 2009

Visual Studio Resource Designer

Visual Studio 2008 was designed to make your life easier.
Now that you're done laughing, it is actually a very nice environment, if you don't mind wasting hours working around a few big bugs and mind-twisting procedures for simple objectives. It takes me back to the good ole days of programming, where the words to live by were, "Save early, save often."
VS2008 is a great reminder that no non-trivial piece of software is perfectly bug-free. Although it tries to be helpful by automatically coordinating your editing to ripple the changes through to the other classes, files, and tool panels in your project, it is very irritating to add a static modifier to a method only to have the entire IDE crash seconds later. I have learned when modifying existing classes, a quick tap of the CTRL-S key to save the edit before VS applies the change in a dozen other places saves me about 10 minutes per crash. I only have 2 GB of memory and a dual-core processor, so obviously my development system is a little slow :-(.
Oh well, next problem. Following some of the Microsoft's tutorials is an exercise in abnormal psychology. How many different write-ups that explain the same procedure can you apply until you realize they are all leading you down a blind alley. That was how I felt when I realized today that there is only one correct way to add an embedded resource to a project that will actually be available at runtime.
I kept seeing the same incorrect instructions over and over: from the Resources folder in the Solution Explorer, select Add > New Item... from the folder's context menu. Great, my bitmap file just got included as an embedded resource, right? Wrong.
The right way: In your project's Properties folder there is a resource object named Resources.resx. Double-click this object to open the Resource Designer; alternatively, you can also double-click the Properties folder and select the Resources tab. At the top of the pane is a toolbar with an Add Resource dropdown. Select Add and choose or create your new resource. Now it gets included as an embedded resource, right? Sorry, wrong again.
Once your new item has been included as a resource in your project, you have to visit the object in the Resources folder. Select the item. In the Properties list, change Build Action to Embedded Resource. OK, now is it an embedded resource? Wait, don't forget to hit Save. Yes, it is at long last, after executing multiple steps, an embedded resource.
So, how much time did you save today? :-/

No comments:

Post a Comment