visual-studio 如何更改 Visual Studio 项目类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1551586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change a Visual Studio project type?
提问by Scott Bussinger
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.
我终于发现 Visual Studio 会跟踪您创建项目的方式(换句话说,您最初选择了哪个项目模板)并稍后根据最初的决定过滤您的选项。该信息作为 <ProjectTypeGuids> 元素保存在 *.csproj 文件中。
Other than just editing the *.csproj file, is there a "right" way to change a project type for an existing project?
除了编辑 *.csproj 文件之外,是否有“正确”的方法来更改现有项目的项目类型?
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!
考虑到该设置的重要性,GUI 中似乎有一个地方可以更改它,但我找不到。谢谢!
回答by JaredPar
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.
小更正:Visual Studio 不跟踪用于创建项目的项目模板。项目系统在很大程度上不知道用于项目的初始模板。项目系统中有几个项目(例如项目类型)与特定模板具有相同的名称,但这是一个巧合,两者都没有得到明确的纠正。
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.
就项目类型而言,唯一真正可以改变的是输出类型。这可以具有值类库、控制台应用程序和 Windows 应用程序。您可以通过转到项目属性页面(右键单击属性)并更改输出类型组合框来更改此设置。
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.
项目系统可能支持其他项目类型,但它们相当少,并且与项目模板没有明确关联。
回答by fotisgpap
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.
在 Visual Studio 中,项目类型作为 GUID 存储在 .csproj XML 文件中。您必须更改 GUID 才能定义所需的新项目类型。
check http://www.mztools.com/Articles/2008/MZ2008017.aspxfor some of the availbale GUIDs
检查http://www.mztools.com/Articles/2008/MZ2008017.aspx以获取一些可用的 GUID
回答by Daniel A. White
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.
我只想将另一个项目添加到您想要的解决方案中,移动文件,然后删除原始项目。
回答by user2161183
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.
您可以在 .csproj 文件中修改它以更改项目类型,例如从 .Net Core 到 .Net Standard。只需更改 blabla 的内容,您就完成了更改。
<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.
但是你应该注意,如果你使用一些外部包,这些包可能与新的项目类型不兼容。因此,您可能需要获取兼容的软件包。
回答by Andrea Antonangeli
I needed to add WPF support to a project of type "Class Library (.NET CORE)" in this way:
我需要以这种方式将 WPF 支持添加到“类库(.NET CORE)”类型的项目中:
- 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
- 编辑 YourProject.csproj(双击它)并修改
<Project Sdk="Microsoft.NET.Sdk">为<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> - 添加
<UseWPF>true</UseWPF>到组中<PropertyGroup> - 重建你的项目
Now you can add a WPF Window
现在您可以添加 WPF 窗口

