مشاركة عبر


كيفية القيام بما يلي: برمجياً إنشاء مشاريع

إلى إنشاء مشروع، استدعاء GetProjectTemplate، ثم ضغط مسار القالب الذي تم إرجاعه إلى AddFromTemplate.

تحتوي قوالب مشروع ملحق اسم ملف.vstemplate و مخزنة في ملفات.zip. للحصول على مسار ملف.vstemplate (في ملف.zip)، استخدم GetProjectTemplate، وثم تمريرها إلى AddFromTemplateلإنشاء مشروع (وأيضا حل، إذا كان ملف هو فتح بالفعل). يمكنك إجراء هذه تشغيل عدة مرة/مرات كما هو مطلوب، وسيتم تمت الإضافة كل مشروع إلى الحل المفتوح حاليا.

يمكن العثور على قوالب مشروع لكافة اللغات في برنامج ملفات\Microsoft ‏‫Visual Studio 10.0\Common7\IDE\ProjectTemplates\ لغة\.

كما يمكنك إنشاء القوالب المخصصة للمشروع الخاص بك. تعيين الدليل الذي يقوم بتخزين القوالب, انقر فوق خيارات القائمة أدوات. في الجزء الأيمن من صندوق الحوار خيارات ، انقر فوق مشاريع و حلول. اكتب مسار القوالب الخاصة بك في المربع الموقع قوالب مشروع مستخدم ‏‫Visual Studio.

مخصص مشروع تتطلب قوالب أسماء الملفات الفريدة التي لا تتعارض مع أسماء الملفات التي تم تعريفها في 10.0\Common7\IDE\مشروعTemplates\ملفات\Microsoft برنامج ‏‫Visual Studio لغة\.

تأكد من استخدام أسماء الملفات الطويلة (مقابل إلى 8dot3). لمزيد من المعلومات، راجع إنشاء المشروع وعنصر قوالب..

ملاحظة

قد تختلف مربعات الحوار وأوامر القائمة التى تشاهدها الان عن تلك الموصوفة في التعليمات اعتماداً على الإعدادات النشطة أو الإصدار الخاص بك. تم تطوير هذه الإجراءات من خلال "إعدادات تطوير عام" النشط. To change your settings, click Import and Export Settings on the Tools menu. لمزيد من المعلومات، راجع العمل مع إعدادات.

إنشاء مشروع ATL

إلى برمجياً إنشاء مشروع

  1. بدء Visual Studioوإنشاء Visual Studioإضافة-في مشروع.

  2. إضافة-في Connectالفئة، إضافة مثال التعليمة البرمجية هو موضح لاحقاً في هذا الموضوع.

  3. تشغيل إضافة-في المشروع وتنشيطه في إضافة-في إدارة .

    إلى للقيام بذلك، انقر فوق إدارة الوظائف الإضافية على إلى ols قائمة وقم بتحديد الوظيفة الإضافية.

مثال

يستخدم المثال التالي GetProjectTemplateو AddFromTemplateإلى إنشاء حسابين مشاريع وحدة التحكم، منها Visual Basicوالآخر #Visual C، في الحل.

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

Sub createProjectsFromTemplates(ByVal dte As DTE2)
    Try
        ' Create a solution with two projects in it, based on project 
        ' templates.
        Dim soln As Solution2 = CType(DTE.Solution, _
        Solution2)
        Dim csTemplatePath As String
        Dim vbTemplatePath As String
        Dim csPrjPath As String = _
        "C:\UserFiles\user1\addins\MyCSProject"
        Dim vbPrjPath As String = _
        "C:\UserFiles\user1\addins\MyVBProject"

        ' Get the project template path for a C# console project.
        ' Console Application is the template name that appears in the 
        ' right pane, "CSharp" is the Language(vstemplate) as seen in 
        ' the registry.
        csTemplatePath = soln.GetProjectTemplate _
        ("ConsoleApplication.zip", "CSharp")
        MsgBox("C# template path: " & csTemplatePath)
        ' Get the project template path for a Visual Basic
        ' console project.
        ' "vbproj: is the DefaultProjectExtension as seen in the 
        ' registry.
        vbTemplatePath = soln.GetProjectTemplate _
        ("ConsoleApplication.zip", "vbproj")
        MsgBox("Visual Basic template path: " & vbTemplatePath)
        ' Create a new C# console project using the template obtained 
        ' above.
        soln.AddFromTemplate(csTemplatePath, csPrjPath, _
          "New CSharp Console Project", False)
        ' Create a new Visual Basic console project using the template
        ' obtained above.
        soln.AddFromTemplate(vbTemplatePath, vbPrjPath, _
          "New Visual Basic Console Project", False)
    Catch ex As System.Exception
        MsgBox("ERROR: " & ex.ToString)
    End Try
End Sub
public void OnConnection(object application, ext_ConnectMode 
  connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    createProjectsFromTemplates(_applicationObject);
}

public void createProjectsFromTemplates(DTE2 dte)
{
    try
    {
        // Create a solution with two projects in it, based on project 
        // templates.
        Solution2 soln = (Solution2)dte.Solution;
        string csTemplatePath;
        string vbTemplatePath;
        string csPrjPath = "C:\\UserFiles\\user1\\addins\\MyCSProject";
        string vbPrjPath = "C:\\UserFiles\\user1\\addins\\MyVBProject";
        // Get the project template path for a C# console project.
        // Console Application is the template name that appears in 
        // the right pane. "CSharp" is the Language(vstemplate) as seen 
        // in the registry.
        csTemplatePath = soln.GetProjectTemplate("ConsoleApplication.zip", 
          "CSharp");
        System.Windows.Forms.MessageBox.Show("C# template path: " + 
          csTemplatePath);
        // Get the project template path for a Visual Basic console
        // project.
        // "vbproj: is the DefaultProjectExtension as seen in the 
        // registry.
        vbTemplatePath = soln.GetProjectTemplate("ConsoleApplication.zip", 
          "vbproj");
        System.Windows.Forms.MessageBox.Show("Visual Basic template path: " + 
          vbTemplatePath);
        // Create a new C# console project using the template obtained 
        // above.
        soln.AddFromTemplate(csTemplatePath, csPrjPath, "New CSharp 
          Console Project", false);
        // Create a new Visual Basic console project using the template 
        // obtained above.
        soln.AddFromTemplate(vbTemplatePath, vbPrjPath, "New VB Console 
          Project", false);
    }
    catch (System.Exception ex)
    {
        System.Windows.Forms.MessageBox.Show("ERROR: " + ex.Message);
    }
}

راجع أيضًا:

المهام

كيفية القيام بما يلي: ترجمة و تشغيل أمثلة تعليمات برمجية طراز كائن للتنفيذ التلقائي

كيفية القيام بما يلي: إنشاء عناصر مشروع برمجياً

المبادئ

التعامل مع Visual أساسى و Visual C# للمشاريع

التعامل مع مشاريع C + + Visual Basic

موارد أخرى

التحكم في الحل و الخاص مشاريع