如何更改默认的C ++模板文件?

时间:2019-04-09 15:48:56

标签: c++ visual-studio visual-studio-2019 file-templates

我正在使用Visual Studio 2019,每当我创建一个新的C ++项目时,它将使用以下代码为我提供一个默认文件:

// Template Test.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

int main()
{
    std::cout << "Hello World!\n"; 
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file

这是太多不必要的信息,需要一分钟时间将其更改为我真正想要的;

// Template Test.cpp : This file contains the 'main' function. Program execution begins and ends there.


#include <iostream>

using namespace std;

int main() {
    cout << "Hello World!\n"; 
}

这并不需要很多时间,但是每次在VS 19中创建新的C ++控制台项目时,我都必须这样做。

在我的计算机上进行了快速搜索之后,我在以下位置找到了一个名为“模板”的文件夹:

  

C:\ Users \ yale \ Documents \ Visual Studio 2019 \ Templates

此文件的子目录会让我认为这是正确的位置,但是据我所知,这些文件夹都没有任何模板文件。

如何使用Visual Studio 2019修改C ++中不同项目的模板文件?

1 个答案:

答案 0 :(得分:0)

您可以通过两种方式选择它们。

使用导出模板向导:

Visual Studio提供了可用于更新现有模板的导出模板向导:

  • 从菜单栏中选择File> New> Project。
  • 选择要更新的模板,然后继续操作 创建新项目的步骤。
  • 在Visual Studio中修改项目。例如,更改输出 在项目中键入或添加新文件。
  • 在“项目”菜单上,选择“导出模板”。    将打开“导出模板向导”。
  • 按照向导中的提示将模板导出为.zip 文件。
  • (可选)将.zip文件放在以下目录中: %USERPROFILE%\ Documents \ Visual Studio \ Templates \ ProjectTemplates使其可用于 选择。如果您未选择 选项自动将模板导入到Visual Studio中的 导出模板向导。
  • 删除旧模板.zip文件。

要手动更新现有模板,请执行以下操作:

  • 找到包含模板的.zip文件。用户项目 模板位于%USERPROFILE%\ Documents \ Visual Studio \ Templates \ ProjectTemplates。
  • 提取.zip文件。
  • 修改或删除当前模板文件,或将新文件添加到 模板。
  • 打开,修改和保存.vstemplate XML文件以处理更新的 行为或新文件。
  • 选择模板中的文件,然后单击鼠标右键或 上下文菜单,然后选择发送到>压缩(压缩)文件夹。的 您选择的文件被压缩为.zip文件。
  • 将新的.zip文件放在与旧的.zip文件相同的目录中。
  • 删除提取的模板文件和旧的模板.zip文件。

此外,您可以访问source page了解更多详细信息。

相关问题