Aracılığıyla paylaş


Solution2.AddFromFile Yöntem (String, Boolean)

Proje zaten sistemde depolanan bir proje dosyasını temel alan bir çözüm ekler.

Ad alanı:  EnvDTE80
Derleme:  EnvDTE80 (EnvDTE80.dll içinde)

Sözdizimi

'Bildirim
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

Parametreler

  • FileName
    Tür: System.String
    Gerekli.Proje dosyasının tam yolu ve dosya adı.
  • Exclusive
    Tür: System.Boolean
    İsteğe Bağlı.Projenin geçerli çözümü ya da kendi çözüm yükler gösterir; trueGeçerli çözüm kapatılır ve yeni bir çözüm için proje eklenir, false proje var, açık çözüme eklenip eklenmediğini.

Dönüş Değeri

Tür: EnvDTE.Project
Project nesnesi

Notlar

Kullanabileceğiniz LaunchWizard yöntemi yerine AddFromFile yürütme sırasında kullanıcı arabirimi (UI) bastırmak istiyorsanız, Sihirbazı çalıştırmak için.LaunchWizardKullanıcı Arabirimi devre dışı bırakmanızı sağlar bir parametreye sahiptir.

Örnekler

Bu eklenti kodu çalıştırma hakkında daha fazla bilgi için bkz: Nasıl yapılır: derlemek ve Otomasyon nesne modeli kod örneklerini çalıştırmak.

Aşağıdaki örnek, bir çözüm oluşturmak ve varolan bir projeye eklemek gösterilmiştir.

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 Güvenliği

Ayrıca bkz.

Başvuru

Solution2 Arabirim

AddFromFile Fazla Yük

EnvDTE80 Ad Alanı