Share via


Solution2.AddFromTemplate 메서드

기존 프로젝트 파일 및 해당 파일에 포함되어 있는 모든 항목 또는 하위 디렉터리를 지정된 위치에 복사하고 이를 솔루션에 추가합니다.

네임스페이스:  EnvDTE80
어셈블리:  EnvDTE80(EnvDTE80.dll)

구문

‘선언
Function AddFromTemplate ( _
    FileName As String, _
    Destination As String, _
    ProjectName As String, _
    Exclusive As Boolean _
) As Project
Project AddFromTemplate(
    string FileName,
    string Destination,
    string ProjectName,
    bool Exclusive
)
Project^ AddFromTemplate(
    [InAttribute] String^ FileName, 
    [InAttribute] String^ Destination, 
    [InAttribute] String^ ProjectName, 
    [InAttribute] bool Exclusive
)
abstract AddFromTemplate : 
        FileName:string * 
        Destination:string * 
        ProjectName:string * 
        Exclusive:bool -> Project
function AddFromTemplate(
    FileName : String, 
    Destination : String, 
    ProjectName : String, 
    Exclusive : boolean
) : Project

매개 변수

  • FileName
    형식: String

    필수 요소. 템플릿 프로젝트 파일의 전체 경로 및 확장명이 있는 파일 이름입니다.

  • Destination
    형식: String

    필수 요소. FileName의 내용을 복사할 대상 디렉터리의 전체 경로입니다.

  • ProjectName
    형식: String

    필수 요소. 대상 디렉터리에 있는 프로젝트 파일의 이름이며 확장명을 포함해야 합니다. 표시되는 이름은 ProjectName에서 파생됩니다.

  • Exclusive
    형식: Boolean

    선택 사항입니다. 프로젝트를 현재 솔루션에 로드할지 아니면 사용자 고유의 솔루션에 로드할지 여부를 나타냅니다. 현재 솔루션을 닫고 새 솔루션에 프로젝트를 추가하면 true이고, 기존의 열려 있는 솔루션에 프로젝트를 추가하면 false입니다.

반환 값

형식: Project
Project 개체입니다.

설명

솔루션 탐색기에서 표시되는 프로젝트의 이름은 파일 확장명이 없는 ProjectName 입니다. 새로운 프로젝트 파일 이름이 이미 대상에 존재하는 경우, AddFromTemplate을를은 실패합니다.

참고

Visual Basic 및 Visual C# 프로젝트의 경우 반환되는 Project 개체의 값은 Nothing이거나 nullNull 참조(Visual Basic의 경우 Nothing)입니다.ProjectName 매개 변수를 사용하여 DTE.Solution.Projects 컬렉션을 반복하여 만든 Project 개체를 찾아 새로 만든 프로젝트를 확인할 수 있습니다.

예제

이 추가 기능 코드를 실행하는 방법에 대한 내용은 방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행을 참조하십시오.

다음 예제에서는 솔루션을 만들고 콘솔 응용 프로그램 프로젝트를 추가합니다.

Public Sub OnConnection(ByVal application As Object, _
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    SolutionExample(_applicationObject)
End Sub

Sub SolutionExample(ByVal dte As DTE2)
    ' This function creates a solution and adds a Visual Basic Console
    ' project to it.
    Try
        Dim soln As Solution2 = CType(DTE.Solution, Solution2)
        Dim vbTemplatePath As String
        ' This path must exist on your computer.
        ' Replace <file path> below with an actual path.
        Dim vbPrjPath As String = "<file path>"
        MsgBox("starting")
        ' Get the project template path for a Visual Basic console project.
        vbTemplatePath = soln.GetProjectTemplate _
        ("ConsoleApplication.zip", "VisualBasic")
        ' Create a new C# Console project using 
        ' the template obtained above.
        soln.AddFromTemplate(vbTemplatePath, vbPrjPath, _
        "New Visual Basic Console Project", False)
        MsgBox("done")
    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst,
 ref System.Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    SolutionExample((DTE2)_applicationObject);
}

public void SolutionExample(DTE2 dte)
{
    // This function creates a solution and adds a Visual C# Console
    // project to it.
    try{
        Solution2 soln = (Solution2)_applicationObject.Solution;
        String csTemplatePath;
        // The file path must exist on your computer.
        // Replace <file path> below with an actual path.
        String csPrjPath = "<file path>";
    "<file path>MessageBox.Show("Starting...");
"<file path>"<file path>csTemplatePath = 
soln.GetProjectTemplate("ConsoleApplication.zip", "CSharp");
        // Create a new C# Console project using the template obtained 
        // above.
        soln.AddFromTemplate(csTemplatePath, csPrjPath,
 "New CSharp Console Project", false);
        MessageBox.Show("Done!");
    }
    catch(SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}

.NET Framework 보안

참고 항목

참조

Solution2 인터페이스

EnvDTE80 네임스페이스