共用方式為


Solution2.AddFromFile 方法 (String, Boolean)

根據已經儲存於系統中的專案檔,將專案加入至方案。

命名空間:  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
    型別:System.String
    必要項。專案檔的完整路徑和檔名。
  • Exclusive
    型別:System.Boolean
    選擇項。指出專案要載入目前的方案還是它自己的方案。如果目前方案已關閉,且要將專案加入至新方案,則為 true;如果要將專案加入至現有的已開啟方案,則為 false。

傳回值

型別:EnvDTE.Project
Project 物件。

實作

_Solution.AddFromFile(String, Boolean)

備註

您可以使用 LaunchWizard 方法,而非 AddFromFile 來執行精靈,如果您想要在執行期間隱藏其使用者介面 (UI)。 LaunchWizard 擁有一個可讓您停用 UI 的參數。

範例

如需如何執行增益集程式碼的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例

下列範例示範如何建立方案,並加入現有的專案。

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 介面

AddFromFile 多載

EnvDTE80 命名空間