19

While setting up my Prism WPF solution I had added a project as Class library. Just realized I want it as a WPF user control library to add resource dictionaries and other WPF related stuff. Is there a way to convert my class library project to WPF user control library project? (Project properties just has the option to convert between Console, Class library, Windows app!)

Kara
  • 6,115
  • 16
  • 50
  • 57
ioWint
  • 1,609
  • 3
  • 16
  • 34

3 Answers3

29

You need to add the following to your project file;

Under the <FileAlignment> element

<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

You may also want to insure you've the following references added within the <ItemGroup> element;

  • <Reference Include="WindowsBase" />
  • <Reference Include="PresentationCore" />
  • <Reference Include="PresentationFramework" />
  • <Reference Include="System.Xaml" />
obaylis
  • 2,904
  • 4
  • 39
  • 66
  • There is a missing ending slash on the last reference (System.Xaml). Without that it won't load correctly. – Jordy Boom Jun 25 '14 at 15:21
  • 2
    Very helpful. Plz note that `` will go at the same level as `` node, not under it as described in the answer. – dotNET Jan 02 '15 at 13:19
  • 1
    Look [here](http://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs) for other known GUIDs – LuckyLikey Jun 24 '15 at 06:50
  • Another difference I noted when comparing a Class Library to a WPF Class Library is the `` element. For a Class Library it was `Windows` and for a WPF Class Library it was `Custom`. Once I changed this in my Class Library project file (along with `ProjectTypeGuids`), the project loaded as WPF Class Library. – Étienne Laneville Jul 14 '20 at 17:50
3

it is not an easy change through the project properties (alt+enter). you need to manually edit the .proj file in an editor ( say notepad / textpad) when you compare a classlibrary project and a WPF Usercontrol library projects .proj file you will find the difference in them is through the nodes in the node.

you need to add ProjectTypeGuids , WarningLevel and TargetFrameworkProfile . it is my understanding, they started to dictate a project type through the PRojectTypeGuids node! which is really cool!

create a class library project and a WPF usercontrol library project and open the .proj files in an editor to compare, you should be able to figure out what i am talking here!

ioWint
  • 1,609
  • 3
  • 16
  • 34
0

It's easy in .Net 6, just enable UseWPF under PropertyGroup, and change TargetFramework node to 'net6.0-windows'. Like below:

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
kelly
  • 1