46

I finally figured out that Visual Studio keeps track of how you create a project (in other words which project template you select initially) and filters your options later based on that initial decision. The information is kept in the *.csproj file as a <ProjectTypeGuids> element.

Other than just editing the *.csproj file, is there a "right" way to change a project type for an existing project?

Considering the significance of that setting it seems likely there's a place in the GUI to change it, but I couldn't find one. Thanks!

Scott Bussinger
  • 2,767
  • 4
  • 28
  • 29

5 Answers5

27

Small correction: Visual Studio does not keep track of the project template used to create a project. The project system is largely unaware of the initial template used for a project. There are several items in the project system (Project Type for instance) which have the same name as specific templates but this is a coincidence and the two are not definitively corrected.

The only thing that can really be changed in terms of the project type is essentially the output type. This can have value Class Library, Console Application and Windows Application. You can change this by going to the project property page (right click Properties) and change the Output Type combo box.

It is possible to have other project types supported by the project system but they are fairly few and are not definitively associated with a project template.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • 11
    You're correct that VS doesn't remember which specific template was used to create the project, but it absolutely classifies the project as being of a particular kind based on information in that template and apparently there's no UI to fix it once created. See my comment to Daniel above for an example of the effects of this choice. When I wrote my original question I had mentioned the XML element the information in stored in, but I see StackOverflow system removed it. I'll edit it back in, but it's the <ProjectTypeGuids> element in the *.csproj file that stores the kind of project. – Scott Bussinger Oct 11 '09 at 23:16
  • @JaredPar - Thanks, I have long wondered how to do this and you're solution worked for me! – nexus-bytes Sep 25 '12 at 02:15
25

In visual studio the project type is stored inside the .csproj XML file as GUID. You have to change the GUID to define the new project type you want.

check http://www.mztools.com/Articles/2008/MZ2008017.aspx for some of the availbale GUIDs

fotisgpap
  • 297
  • 4
  • 9
6

Why do you want to change this?

I would just add another project to the solution with the one you want, move the files, then remove the original project.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • 5
    Right click on a project and bring up the "Add" menu. What choices do you have? If you don't create the project using one of the WPF templates you won't have things like "User Control" or "Resource Dictionary" as options. If you didn't start as a WPF project, you won't even have "Resource Dictionary" as an option under "New Item...". I've done the shuffle you describe, that it's a pain if there are lots of items and the whole thing is under version control. All that to simply change the kind of project seems silly. – Scott Bussinger Oct 11 '09 at 23:04
  • 6
    @Scott: It may seem kind of silly, but there could be more to a "kind of project" than just the GUID in the property. Since the project file itself is defined by the template you used when you created the project, you may (and should!) find other differences, like different s of .targets files and the like. If you don't want to do the shuffle, you should at least create an empty project of the type you want and diff the project file against an empty project of the type you have. In addition to the , make any other relevant changes as well. – JaredReisinger Apr 25 '13 at 03:12
  • making new project is good. but if you want to give new project same name you would have problems. here is easy fix, right click on project and select "unload project" then "remove", then right click on solution and select "Open folder in File Explorer", then find your project folder and rename that to something else. create new project with the name you want and copy existing items there. also to include existing files in new project you can add existing item (shift+alt+A). – M.kazem Akhgary Jun 17 '17 at 09:33
0

You can modify it in the .csproj file to change the project type, for instance from .Net Core to .Net Standard. Just by changing the content of blabla you are done with the changes.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AssemblyName>...</AssemblyName>
    <RootNamespace>...</RootNamespace>
  </PropertyGroup>

</Project>

But you should take note if you use some external packages, the packages might not be compatible with the new project type. So, you may need to get the compatible packages.

Babak
  • 26
  • 2
0

I needed to add WPF support to a project of type "Class Library (.NET CORE)" in this way:

  • edit YourProject.csproj (double click on it) and modify <Project Sdk="Microsoft.NET.Sdk"> to <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  • add <UseWPF>true</UseWPF> in the group <PropertyGroup>
  • rebuild YourProject

Now you can add a WPF Window

Andrea Antonangeli
  • 1,242
  • 1
  • 21
  • 32