小编Man*_*nis的帖子

如何以编程方式将文件添加到Visual Studio模板?

我已经为.net核心应用程序创建了Visual Studio项目模板。使用此模板创建新项目时,我希望能够在Azure身份验证和身份验证之间进行选择。为了实现这一点,我创建了一个向导。根据向导上选择的选项,项目中必须包含一些其他文件。我的问题是我不知道如何将这些额外的文件添加到我的项目中。

第一种方法

首先,我创建了一个项目模板,并尝试将其内容添加到我的项目中。

AzureAuthentication.vs模板

<VSTemplate>
    <TemplateData>
        <!-- code removed for clarity -->
    </TemplateData>
    <TemplateContent>
        <Folder Name="Models" TargetFolderName="Models">
            <ProjectItem ReplaceParameters="true" TargetFileName="RefreshTokenResponse.cs">RefreshTokenResponse.cs</ProjectItem>
        </Folder>
        <Folder Name="Controllers" TargetFolderName="Controllers">
            <ProjectItem ReplaceParameters="true" TargetFileName="UserController.cs">UserController.cs</ProjectItem>
        </Folder>
    </TemplateContent>
</VSTemplate>
Run Code Online (Sandbox Code Playgroud)

WizardImplementation.cs

public class WizardImplementation : IWizard {
    public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) {
        dte = automationObject as DTE;

        // code removed for clarity
    }

    public void ProjectFinishedGenerating(Project project) {
        switch (authenticationType) {
            default: break;
            case AuthenticationType.Azure: {
                    // code removed for clarity

                    using …
Run Code Online (Sandbox Code Playgroud)

visual-studio visual-studio-templates vsix visual-studio-2017

5
推荐指数
1
解决办法
387
查看次数