Solution3.AddFromTemplate 메서드 (String, String, String, Boolean)

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

네임스페이스:  EnvDTE90
어셈블리:  EnvDTE90(EnvDTE90.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
    형식: System.String
    필수적 요소로서,템플릿 프로젝트 파일의 전체 경로 및 확장명이 있는 파일 이름입니다.
  • Destination
    형식: System.String
    필수적 요소로서,FileName의 내용을 복사할 대상 디렉터리의 전체 경로입니다.
  • ProjectName
    형식: System.String
    필수적 요소로서,대상 디렉터리에 있는 프로젝트 파일의 이름이며확장명을 포함해야 합니다.표시되는 이름은 ProjectName에서 파생됩니다.
  • Exclusive
    형식: System.Boolean
    선택적 요소로서,프로젝트를 현재 솔루션에 로드할지 아니면 사용자 고유의 솔루션에 로드할지 여부를 나타냅니다. 현재 솔루션을 닫고 새 솔루션에 프로젝트를 추가하면 true이고, 기존의 열려 있는 솔루션에 프로젝트를 추가하면 false입니다.

반환 값

형식: EnvDTE.Project
Project 개체입니다.

구현

Solution2.AddFromTemplate(String, String, String, Boolean)

설명

솔루션 탐색기에서 표시되는 프로젝트의 이름은 파일 확장명이 없는 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 C# Console
    ' project to it.
    Try
        Dim soln As Solution3 = CType(DTE.Solution, Solution3)
        Dim csTemplatePath As String
        ' This path must exist on your computer.
        ' Replace <file path> below with an actual path.
        Dim csPrjPath As String = "<file path>"
        MsgBox("starting")
        ' Get the project template path for a C# console project.
        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)
        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{
        Solution3 soln = (Solution3)_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 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

Solution3 인터페이스

AddFromTemplate 오버로드

EnvDTE90 네임스페이스

기타 리소스

방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행