WPF targets in Windows Forms project

I might be the last person to find this out, I don’t know – in that case, regard it as a note to self.

I was working with a Windows Forms project, using an ElementHost to embed a WPF control. I was trying to create a WPF UserControl and it just wasn’t working, because Visual Studio didn’t seem to build the control correctly. For instance, the InitializeComponent method call in the constructor of the UserControl resulted in an error message. I looked around for a while and was a bit confused about possible sources of the problem. Then I compared two project files and found out that the targets for WPF are simply not there when the project wasn’t originally created to target WPF – kind of obvious once you know it, but then what isn’t…

I edited the project file of the Windows Forms project to include this line:

<Import Project="$(MSBuildBinPath)Microsoft.WinFX.targets" />

And voilá, suddenly everything builds just fine. Duh.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s