Eiríkur Nilsson’s Weblog

Programming Adventures
RSS icon Email icon Home icon
  • My Visual Studio Settings

    Posted on April 21st, 2010 eirikurn 1 comment

    Visual Studio is my favorite IDE as it supports all kinds of development. It has nice project management features, the best Intellisense and excellent plugins like Resharper and Coderush that really bring the whole experience up a level.

    What has made it so successful is that everything about it can be configured, either through built in settings or using plugins. This allows it to fit a wide range of needs and everybody can tweak it to their liking.

    These days I’m migrating to Visual Studio 2010 so I thought I’d log here the settings that I use. These are just a couple of the settings that I use. If I remember more, I’ll update this post. I also plan to write a post covering some of the lesser known features of VS2010 that I use on a regular basis.

    I won’t argue that these are the correct settings, nor do I expect everyone to follow my lead. Instead I simply wish to demonstrate things that are configurable and perhaps show people something they didn’t know was possible.

    Keyboard shortcuts

    Since I really like consistency, I configure the environment to use shortcut keys found in most other environments. To configure this, go to Tools > Options > Environment > Keyboard. You can search for a command by name and then assign or override its shortcut. Just remember to disable any other command using the same shortcut, otherwise you might end up with an unpredictable environment, which is annoying at best.

    • Ctrl-W: File.Close
    • Ctrl-Shift-W: File.CloseAllButThis
    • Ctrl-Shift-S: File.SaveSelectedItemsAs
    • Ctrl-Shift-N: Project.NewFolder

    Text Editor

    Visual Studio Text Editors SettingsFor the text editor, I start off by configuring my preference in the All Languages area, and then I tweak specific languages.

    All Languages > General > Line numbers: It’s really handy to always see the line numbers in your file. Especially when you have to manually trace a call stack. It also keeps you aware of the size of your files.

    All Languages > Tabs: I generally prefer using a single character for indentation and letting each programmer choose its display, so I make Visual Studio “Keep Tabs” and display them as 4 characters in most languages.

    I change this in the XML editor, and sometimes even HTML and JS, to be 2 characters since these languages sometimes have much deeper indentation.

    JScript > Formatting: These formatting features can be really annoying. They always seem to get in the way of my coding style, messing up indentation, brackets, if clauses and so on. Which is why I turn them off.

    It seems to me that good javascript code doesn’t follow the same rigid formatting rules that statically typed code follows. I would even say Javascript developers like to spend more time tweaking their syntax to look good, in an artistic kind of way.

    CSS > Miscellaneous and HTML > Validation: The built-in validation for HTML and CSS isn’t great. It doesn’t support the newest standards, like HTML 5 and CSS 3. It only validates open files, making the error panel quite unpredictable. It also shows validation errors as warnings (by default), often hiding real warnings in a sea of validation warnings. So here you can turn them off.

    Miscellaneous

    Projects and Solutions > General > Save new projects when created: I really like being able to turn this off. It makes the environment more like the olden VB days where you can throw up a new project, put down some code to test some random thing you just thought about, and when you’re done, you just close it and its gone. No bunch of ConsoleApplication# lying around everywhere.

    I hope this post inspires you to scan through the Options dialog for new settings to streamline your development. If you find anything cool, or have a setting that you always change when you set up your studio, be sure to share it in the comments.

  • Copying Files and Directories With Progress in C#

    Posted on February 13th, 2010 eirikurn No comments

    The .Net Framework doesn’t have any method to copy directories recursively. It doesn’t either support getting progress on file copies. So I decided to write two extension methods to fill up the gap.

    Features

    These extension methods are attached to FileInfo and DirectoryInfo and allow you to:

    • Copy a single file with progress notifications.
    • Copy a directory recursively with or without progress notifications.
    • The progress updates includes the number of bytes transferred and the total number of bytes being copied, both for the currently transferring file, and for the whole operation.
    • The progress updates also include the filename being currently copied.

    Behind the scenes I use Interop to call CopyFileEx and the code is fairly optimized but it should also be simple to adapt it to your needs.

    Usage

    To copy a file and display progress, you first create a FileInfo instance for the file you want to copy, then you call the new extension method.

    var fileInfo = new FileInfo("C:/Copy/This.file");
    fileInfo.CopyTo("C:/Dest/Folder", (p) => {
        Progress = (double)p.BytesTransferred / p.TotalBytes;
    });

    If you want to copy a folder, you get some more progress information, as you can see here:

    var dirInfo = new DirectoryInfo("C:/Copy/From/");
    dirInfo.CopyTo("C:/Copy/To/", (p) => {
        TotalProgress = (double)p.BytesTransferred / p.TotalBytes;
        FileProgress = (double)p.CurrentFileTransferred / p.CurrentFileSize;
        CurrentFile = p.CurrentFileName;
    });

    Download

    The code can be downloaded here, CopyExtensions.cs. Enjoy!

    Creative Commons License

    This work is in the Public Domain.

  • The Start Of Something Great

    Posted on March 23rd, 2009 eirikurn 4 comments

    So here it begins, my first blog post.

    I hope to make this a personal domain for collecting thoughts and ideas in development. This will be primarily a code blog but hopefully with time I will start developing and sharing project management and productivity related posts.

    I’m a technology carnivore so I consume every possible language, framework and bubble. I’m most interested in front end development, recent adventures include desktop applications using C# and WPF, 3d worlds using Python and Panda3D, websites using CSS and Javascript and RIA’s using Actionscript 3.0. So these are domains I might start blogging about.

    … or I might jump into something completely different, I heard Silverlight 3.0 was just being announced ;)