Visual Studio: Move referenced DLL to different directory after Build

July 20, 2010 MSBuild

If you need to move a referenced DLL to a different directory after build, add these commands to the "Post Build event command line" box in the "Build Events" tab of the project properties:

mkdir $(TargetDir)dir
move $(TargetDir)myDLL.dll $(TargetDir)dir\myDLL.dll

Xna: Load Texture2D from Embedded Resource

July 03, 2010 Embedded Resources

If you're writing an app which uses Xna, you may need to load a texture from an embedded resource. Here's how:

First embed the resource in your app. Do so by choosing Embedded Resource as the Build Action in the properties of the resource.

After that you can load the Texture2D using a stream handle to the embedded file.

Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("AppNamespace.Folder.font.bmp"); return Texture2D.FromFile(graphicsDevice, stream);

GetCallingAssembly() can be exchanged with GetExecutingAssembly() if needed. The name of the resource must be fully qualified with the app's namespace and folders. I usually keep my resources in a folder Resources so I would have: AppNamespace.Resources.font.bmp.

Implementing basic Dependency Injection using a Service Container

June 21, 2010 .NET, C#, Dependency Injection, Design Patterns, Service Continer

By extending your Service Container class, a very basic version of dependency injection can be implemented. We'll implement two forms of dependency injection: constructor and property injection.

Read More

500 Downloads of the Same Game

June 09, 2010 .NET, CodePlex, Same Game Xna, WinForms, Xna

My little Xna game that I wrote nearly 2 years ago reached the 500 downloads mark (binaries and source) the other day. With that said, I'd like to say that I'm working on version 2.0.

In version 2.0 I'm going to make the code more event driven. The old code uses the Xna Game class and in the new version I'll be making it WinForms based. Almost a complete rewrite.

My work so far is available through SVN on the project's Codeplex page.

Progress Bar in Windows 7 Taskbars

June 01, 2010 .NET, C#, Windows 7

I decided to add progress bar to the Windows 7 Taskbar in my Timer app.

I started by downloading and compiling the Windows API Code Pack in Release mode. I then added a reference to the Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll files to the project. After that add the lines:

using Microsoft.WindowsAPICodePack.Taskbar;

to your using statements. When the clock starts running I create the progress bar in the taskbar with:

// Initialize progress bar if(TaskbarManager.IsPlatformSupported) { TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal); TaskbarManager.Instance.SetProgressValue(0, (int)this.totalTime.TotalSeconds, this.Handle); }

to stop the progress bar:

// Stop progress bar if(TaskbarManager.IsPlatformSupported) TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress);

and finally to update the progress bar on each tick:

// Update progress bar if(TaskbarManager.IsPlatformSupported) TaskbarManager.Instance.SetProgressValue((int)this.totalTime.TotalSeconds - (int)this.time.TotalSeconds, (int)this.totalTime.TotalSeconds, this.Handle);