简体   繁体   中英

Create Project template from solution folder in visual studio

I want to create project template from folder containing few html/js files. More files can be added on later.

For this, I followed the Getting started with vsix project template .
Simply, there are 2 main steps:

  1. Create project, add required files and then export from project menu - It will generate the zip file in exported templates folder under VS directory in My Docs.
  2. Create VSIX Project (requires VS extension SDK installed) and double click source.extension.vsixmanifest and in Assets add type - project template type and source - above zip file location

Now, since I have Non .Net based files, I need to have solution folder and export it. But when I create solution folder option for exporting is disabled in project menu. Is there any way to export solution folder?

I also tried with empty console project. In this case after installing from vsix (output from project in step 2), the new project is created with empty folder - no html/js files included. Also, the new template is shown under C# project, it would be better if shown under other project type. My csproj file for reference below:

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

  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>Net47</TargetFramework>
    <ApplicationIcon />
    <StartupObject />
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="MyJSFolder\" />
  </ItemGroup>

</Project>

So, how do create project template in this case?

Current version of Visual Studio only could export Project template and Item template, both of them don't include solution folder.

If you want to add solution folder in project template, I suggest you add a custom wizard extension for your project template. And then in RunFinished method to add files to your solution. Because at time of RunStarted method executing, project structure has been created in Temp folder and DTE is trying to read files from Temp folder which are not existing.

Following document introduce how to create custom wizard extension and project template.

https://www.codeproject.com/Articles/391989/Working-with-Project-Template-and-Wizard-Extension

In the RunFinished method to add files with the code in this thread.

https://stackoverflow.com/a/30878880/6593307

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM