Hackviking He killed Chuck Norris, he ruled dancing so he took up a new hobby…

15Aug/160

Visual studio: Dump data to file from immediate window

Friday afternoon I started a test run against an API to sort some file issues out. Saving the result in a List<string> while running to dump it out to a text file when done. Due to bad formatting of the filename I got an unhandled exception. Quick test code doesn't always include try-catch statements where they should as you know. Since the the information was in the list I went ahead and dumped it out to a new text file via the immediate window.

You can more or less run any code via the immediate window as long as everything you need are in the current context. I wrote a short example on how to do this if you ever run into the same issue. Immediate-window-demo on Github.

3Sep/150

Easiest way to embed assembly’s into your executables

I usually write a lot of command line tools for different quick fixes. Distributing them to clients with a lot of attached DLL files are not always the best. They get copied around different servers and sooner or later someone runs them without the proper DLL files present. For quick and dirty tools there might be faulty error handling and the tool fails in a critical moment due to the missing assembly. I usually embed the DLL file into the executable, especially when doing command line tools. By far the easiest way of doing that in .Net is to install a Nuget package called Costura.Fody!

Just install it into the project and build the release and all assembly's get compressed and embedded into the executable. Visit Costura.Fody github page for more information!