Aracılığıyla paylaş


Solution2.AddFromTemplate Yöntem (String, String, String, Boolean)

Kopya varolan bir dosya ve herhangi bir öğe veya alt dizinleri, belirtilen konuma içerir ve çözüme ekler proje.

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

Sözdizimi

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

Parametreler

  • FileName
    Tür: System.String
    Gerekli.Tam yolu ve dosya adı şablonu proje dosyasının uzantısı.
  • Destination
    Tür: System.String
    Gerekli.İçeriğini kopyalamak istediğiniz dizinin tam yolunu FileName.
  • ProjectName
    Tür: System.String
    Gerekli.Hedef dizinde proje dosyasının adı.Bu uzantı içermelidir.Görüntülenen ad türetilir ProjectName.
  • Exclusive
    Tür: System.Boolean
    İsteğe Bağlı.Projenin geçerli çözümde yükler olup olmadığını gösterir veya kendi; trueGeçerli çözüm kapatılır ve yeni bir çözüm için proje eklenir, false , proje için eklenirvarolan, açık çözüm.

Dönüş Değeri

Tür: EnvDTE.Project
Project nesnesi

Yüklenen

_Solution.AddFromTemplate(String, String, String, Boolean)

Açıklamalar

Görüntülenen proje adı Solution Explorer olan ProjectName olmadan dosya uzantısı. AddFromTemplateYeni proje dosyası adı hedef zaten varsa, başarısız olur.

Not

İçin Visual Basic ve Visual C# projects: Döndürülen Project Nesne değeri olan Nothing veya nullnull başvuru (Visual Basic\'te Nothing). Oluşturulan bulabilirsiniz Project yineleme nesne DTE.Solution.Projects kullanarak toplama ProjectName parametresini tanımlamak yeni oluşturulan bir proje.

Ö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 örnekleri çalıştırma.

Aşağıdaki örnek, bir çözüm oluşturur ve konsol uygulama projesine ekler.

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

Ayrıca bkz.

Başvuru

Solution2 Arabirim

AddFromTemplate Fazla Yük

EnvDTE80 Ad Alanı