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 voila, suddenly everything builds just fine. Duh.

Sorry, this blog does not support comments.

I used various blog hosting services since this blog was established in 2005, but unfortunately they turned out to be unreliable in the long term and comment threads were lost in unavoidable transitions. At this time I don't want to enable third-party services for comments since it has become obvious in recent years that these providers invariably monetize information about their visitors and users.

Please use the links in the page footer to get in touch with me. I'm available for conversations on Keybase, Matrix, Mastodon or Twitter, as well as via email.