Share via


Solution2.AddFromFile 메서드

시스템에 이미 저장된 프로젝트 파일을 기반으로 솔루션에 프로젝트를 추가합니다.

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

구문

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

매개 변수

  • FileName
    형식: String

    필수 요소. 프로젝트 파일의 전체 경로와 파일 이름입니다.

  • Exclusive
    형식: Boolean

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

반환 값

형식: Project
Project 개체입니다.

설명

실행하는 동안 해당 사용자 인터페이스(UI)를 표시하지 않으려면 AddFromFile 대신 LaunchWizard 메서드를 사용하여 마법사를 실행할 수 있습니다. LaunchWizard에는 UI를 사용하지 않도록 설정할 수 있는 매개 변수가 있습니다.

예제

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

다음 예제에서는 솔루션을 만들고 기존 프로젝트를 추가하는 방법을 보여 줍니다.

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)
    AddFromFileExample(_applicationObject)
End Sub

Sub AddFromFileExample(ByVal dte As DTE2)
    ' This add-in creates a solution and adds an 
    ' existing project to it.
    Try
        Dim soln As Solution2 =  _
        CType(_applicationObject.Solution, Solution2)
        ' Create a new solution.
        ' Make sure the path below exists on your computer.
        ' You can modify the path.
        soln.Create("c:\temp2", "MyNewSolution")
        ' Add an existing project to the new solution.
        ' Modify the path to a location that contains a
        ' Visual Studio project.
        soln.AddFromFile _
        ' Make sure to set the path below to the default project location on your computer
        ("c:\temp1\Visual Studio 2010\ _  
        Projects\ConsoleApplication\ConsoleApplication\ _
        ConsoleApplication.csproj")
    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.
    AddFromFileExample((DTE2)_applicationObject);
}
public void AddFromFileExample(DTE2 dte)
{
    // This add-in creates a soultion and adds an 
    // existing project to it. 
    try
    {
        Solution2 soln = (Solution2)_applicationObject.Solution;
        // Create a solution.
        // Make sure that the file path specified below
        // exists on your computer.
        // You can modify the path.
        soln.Create("c:\temp2", "MyNewSolution");
        // Add an existing project to the new solution.
        // Modify the path to a location that contains
        // a Visual Studio project.
        soln.AddFromFile("c:\temp1"
\Visual Studio 2010\Projects\ConsoleApplication
\ConsoleApplication\ ConsoleApplication.csproj", true);
        }
    catch(SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}

.NET Framework 보안

참고 항목

참조

Solution2 인터페이스

EnvDTE80 네임스페이스