مشاركة عبر


الإرشادات التفصيلية: لاستخدام Cusإلىm إجراء إلى ترجمة التعليمات برمجية ثنائية إلى الأصلي عند تثبيت

يمكنك تعريف الاجراءات cusإلىm إلى تحديد الأوامر التي يتم تشغيلها بعد تثبيت. على سبيل المثال، في هذه معاينة، يمكنك تحديد إجراء مخصص و تمرير اسم مسار EXE إلى CustomActionData خاصية التحويل البرمجي للملف التنفيذي للتعليمات البرمجية الأصلية بعد تثبيت تطبيق.

ملاحظة

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

إلى إنشاء تطبيق ويب مستعرض إلى نشر

  1. من القائمة File (ملف)، أشر إلى New (جديد)، ثم انقر فوق Project (مشروع).

  2. انقر فوق تطبيق Windows Forms.

  3. بالنسبة الاسم، اكتب BrowserSample، و ثم انقر فوق ‏‏موافق .

  4. في القائمة عرض، انقر فوق تفاصيل.

  5. توسيع الجميع أشكال Windows، ثم قم بسحب لوحة عنصر تحكم إلى الأعلى اليسار في النموذج.

  6. في "مصمم النموذج"، اسحب مربع النص عنصر تحكم و زر عنصر تحكم إلى لوحة عنصر تحكم.

  7. في "مصمم النموذج"، اسحب من متصفح ويب عنصر تحكم أدناه لوحة.

  8. توسيع الحجم نموذج لاحتواء الجميع عناصر التحكم.

  9. في "مصمم النموذج"، انقر فوق لوحة عنصر تحكم.

  10. In the Properties Window, change the Dock property under Layout to Top.

  11. في "مصمم النموذج"، انقر فوق عنصر التحكم متصفح ويب .

  12. In the Properties Window, change the Dock property under Layout to Fill.

  13. في the نموذج مصمم, انقر the زر عنصر تحكم.

  14. In the Properties Window, change the Text property under Appearance to Go.

  15. تغيير الحجم the نموذج, لوحة, مربع نص, زر, و متصفح ويب إلى your preferences.

  16. في the نموذج مصمم, ينقر مزودجا the انتقال زر.

    The عرض تعليمات برمجية for the Form1 ‏‏رمز الملف appears.

  17. إضافة the following تعليمات برمجية, which adds ويب browsing functionality إلى your تطبيق. The text في the مربع نص عنصر تحكم هو the العنوان bar for the متصفح ويب عنصر تحكم, و the إجراء takes place when you انقر the انتقال زر.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate(TextBox1.Text)
    End Sub
    
    private void button1_Click(object sender, EventArgs e)
    {
        webBrowser1.Navigate(textBox1.Text);
    }
    
  18. إلى اختبار the مستعرض, ضغط F5.

    The نموذج opens.

  19. في the صندوق نص, نوع https://www.microsoft.com, و then انقر انتقال.

    The Microsoft ويب موقع appears.

إلى إنشاء the مخصص إجراء فئة

  1. في قائمة ملف ، أشر إلى إضافة، و ثم انقر فوق مشروع جديد.

  2. في the إضافة جديد مشروع حوار صندوق, انقر Windows, و then انقر فئة مكتبة.

  3. في the اسم صندوق, نوع NGenCustomAction, و then انقر ‏‏موافق.

  4. في مشروع قائمة ، انقر فوق إضافة عنصر جديد .

  5. في إضافة عنصر جديد? صندوق حوار انقر فوق عاموثم انقر فوق فئة مثبت. في الاسم صندوق اكتب من NGenCustomActionوثم انقر فوق إضافة.

  6. في من مستكشف الحلول، قم بحذف Class1تعليمات برمجية ملف في مشروع NGenCustomAction.

إلى إضافة التعليمة البرمجية إلى إجراء مخصص

  1. انقر نقراً مزدوجاً فوق رمز NGenCustomAction ملف في مستكشف الحلول (أو سطح التصميم)، ثم انقر فوق عرض تعليمات برمجية لفتح محرر تعليمات برمجية. إضافة التعليمة البرمجية التالية إلى أعلى وحدة نمطية?.

    Imports System.IO
    Imports System.Diagnostics
    
    using System.IO;
    using System.Diagnostics;
    
  2. قم بتحديث إعلان فئة إلى يورث System.Configuration.Install.Installerclass.

    Inherits System.Configuration.Install.Installer
    
    : System.Configuration.Install.Installer
    
  3. في التعليمة البرمجية NGenCustomAction ملف، أضف الأسلوب المساعد التالية لإنشاء تعليمات برمجية للنسخة الأصلية ملف لأي تجميع.

        <System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)> _
    Private Sub ngenCA(ByVal savedState As System.Collections.IDictionary, ByVal ngenCommand As String)
            Dim argsArray As [String]()
    
            If String.Compare(ngenCommand, "install", StringComparison.OrdinalIgnoreCase) = 0 Then
                Dim args As [String] = Context.Parameters("Args")
                If [String].IsNullOrEmpty(args) Then
                    Throw New InstallException("No arguments specified")
                End If
    
                Dim separators As Char() = {";"c}
                argsArray = args.Split(separators)
                'It is Ok to 'ngen uninstall' assemblies which were not installed
                savedState.Add("NgenCAArgs", argsArray)
            Else
                argsArray = DirectCast(savedState("NgenCAArgs"), [String]())
            End If
    
            ' Gets the path to the Framework directory.
            Dim fxPath As String = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()
    
            For i As Integer = 0 To argsArray.Length - 1
                Dim arg As String = argsArray(i)
                ' Quotes the argument, in case it has a space in it.
                arg = """" & arg & """"
    
                Dim command As String = (ngenCommand & " ") + arg
    
                Dim si As New ProcessStartInfo(Path.Combine(fxPath, "ngen.exe"), command)
                si.WindowStyle = ProcessWindowStyle.Hidden
    
                Dim p As Process
    
                Try
                    Context.LogMessage((">>>>" & Path.Combine(fxPath, "ngen.exe ")) + command)
                    p = Process.Start(si)
                    p.WaitForExit()
                Catch ex As Exception
                    Throw New InstallException("Failed to ngen " & arg, ex)
                End Try
            Next
        End Sub
    
            [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
            private void ngenCA(System.Collections.IDictionary savedState, string ngenCommand)
            {
                String[] argsArray;
    
                if (string.Compare(ngenCommand, "install", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    String args = Context.Parameters["Args"];
                    if (String.IsNullOrEmpty(args))
                    {
                        throw new InstallException("No arguments specified");
                    }
    
                    char[] separators = { ';' };
                    argsArray = args.Split(separators);
                    savedState.Add("NgenCAArgs", argsArray); //It is Ok to 'ngen uninstall' assemblies which were not installed
                }
                else
                {
                    argsArray = (String[])savedState["NgenCAArgs"];
                }
    
                // Gets the path to the Framework directory.
                string fxPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
    
                for (int i = 0; i < argsArray.Length; ++i)
                {
                    string arg = argsArray[i];
                    // Quotes the argument, in case it has a space in it.
                    arg = "\"" + arg + "\"";
    
                    string command = ngenCommand + " " + arg;
    
                    ProcessStartInfo si = new ProcessStartInfo(Path.Combine(fxPath, "ngen.exe"), command);
                    si.WindowStyle = ProcessWindowStyle.Hidden;
    
                    Process p;
    
                    try
                    {
                        Context.LogMessage(">>>>" + Path.Combine(fxPath, "ngen.exe ") + command);
                        p = Process.Start(si);
                        p.WaitForExit();
                    }
                    catch (Exception ex)
                    {
                        throw new InstallException("Failed to ngen " + arg, ex);
                    }
                }
            }
    
    
  4. في التعليمة البرمجية NGenCustomAction ملف، قم بإضافة إجراء التالي لتجاوز Install، Commit، Rollback، و Uninstallإجراءات فئة. الأساسية

    <System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)> _
    Public Overloads Overrides Sub Install(ByVal savedState As System.Collections.IDictionary)
        MyBase.Install(savedState)
        Context.LogMessage(">>>> ngenCA: install")
        ngenCA(savedState, "install")
    End Sub
    
    <System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)> _
    Public Overrides Sub Commit(ByVal savedState As System.Collections.IDictionary)
        MyBase.Commit(savedState)
        Context.LogMessage(">>>> ngenCA: commit")
    End Sub
    
    <System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)> _
    Public Overloads Overrides Sub Uninstall(ByVal savedState As System.Collections.IDictionary)
        MyBase.Uninstall(savedState)
        Context.LogMessage(">>>> ngenCA: uninstall")
        ngenCA(savedState, "uninstall")
    End Sub
    
    <System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)> _
    Public Overloads Overrides Sub Rollback(ByVal savedState As System.Collections.IDictionary)
        MyBase.Rollback(savedState)
        Context.LogMessage(">>>> ngenCA: rollback")
        ngenCA(savedState, "uninstall")
    End Sub
    
    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Install(System.Collections.IDictionary savedState)
    {
        base.Install(savedState);
        Context.LogMessage(">>>> ngenCA: install");
        ngenCA(savedState, "install");
    }
    
    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Commit(IDictionary savedState)
    {
        base.Commit(savedState);
        Context.LogMessage(">>>> ngenCA: commit");
    }
    
    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Uninstall(System.Collections.IDictionary savedState)
    {
        base.Uninstall(savedState);
        Context.LogMessage(">>>> ngenCA: uninstall");
        ngenCA(savedState, "uninstall");
    }
    
    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Rollback(System.Collections.IDictionary savedState)
    {
        base.Rollback(savedState);
        Context.LogMessage(">>>> ngenCA: rollback");
        ngenCA(savedState, "uninstall");
    }
    

إلى إضافة مشروع نشر الخاص بتطبيق "نماذج مستعرض"

  1. في قائمة ملف ، أشر إلى إضافة، و ثم انقر فوق مشروع جديد.

  2. في إضافة مشروع جديد صندوق حوار توسيع أنواع غير ذلك من المشروع، قم بتوسيع مشاريع الإعداد والنشر، انقر فوق مثبت Studio Visual Basicوثم انقر فوق إعداد مشروع.

  3. في المربع الاسم ، اكتب من مستعرض نموذج مثبت، ومن ثم انقر فوق ‏‏موافق .

  4. في محرر ملف النظام، تحديد مجلد التطبيقات. تشغيل theActiتشغيل قائمة, انقر إضافة.

    مجموعة إخراج المشروع إضافة صندوق حوار تظهر.

  5. في صندوق التحرير والسرد المنسدلة مشروع, تحديد BrowserSample انقر فوق إخراج مشروع وثم انقر فوق ‏‏موافق .

  6. في محرر ملف النظام، تحديد مجلد التطبيقات. تشغيل theActiتشغيل قائمة, انقر إضافة.

    مجموعة إخراج المشروع إضافة صندوق حوار تظهر.

  7. في المنسدلة مشروع المنسدلة صندوق التحرير والسرد، تحديد NGenCustomAction، وانقر فوق إخراج مشروع، و ثم انقر فوق ‏‏موافق .

لإضافة NGEN إجراء مخصص إلى مشروع الإعداد

  1. في من مستكشف الحلول، انقر فوق مشروع مستعرض نموذج مثبت.

  2. في قائمة عرض ، أشر إلى محرر، و ثم انقر فوق الاجراءات مخصصة.

  3. في محرر الاجراءات مخصصة، تحديد الاجراءات مخصصة عقدة.

  4. في قائمة إجراء ، انقر فوق إضافة إجراء مخصص .

  5. في صندوق الحوار تحديد عنصر في مشروع ، انقر نقراً مزدوجاً فوق مجلد التطبيقات، انقر فوق الإخراج الأساسي من NGenCustomAction (نشط) ، ثم انقر فوق ‏‏موافق

    تتم تمت الإضافة "إجراء مخصص في" منشئ الصورة الأصلية "إلى الجميع العقد الإجراء المخصص الرابع.

  6. في العقدة يثّبت ، انقر فوق إخراج أساسي من NGenCustomAction (نشط).

  7. في الإطار خصائص ، تغيير CusإلىmActionData خاصية إلى /Args="[دليل الهدف]BrowserSample.exe". قم بتضمين علامات الاقتباس.

    ملاحظة

    خاصية [دليل الهدف] هو الموقع تثبيت تنفيذي. يستخدم إجراء المخصص ngen.exe لتحويل المثبتة في تنفيذي إلى نسخة أصلية.

  8. في من مستكشف الحل، انقر فوق من مستعرض نموذج مثبت إعداد مشروع.

  9. من قائمة بنية ، انقر فوق إنشاء مثبت نماذج مستعرض.

للتحقق من تعليمة برمجية أصلية الجيل

  1. انتقل إلى مجلد التثبيت والعثور BrowserSample.exe ملف. ل مثال%PROGRAMFILES%\CompanyName\Brower مثبت\BrowserSample.exe نموذج.

  2. في تعجيل أوامر ‏‫Visual Studio، تحقق من أنه تم precompiled الملف التنفيذي إلى تعليمات برمجية الأصلية عن طريق تشغيل التعليمة البرمجية التالية:

    ngen.exe display FullPathToExe
    

    على سبيل المثال، قد تقوم بتشغيل الأمر التالي:

    ngen.exe display "C:\Program Files (x86)\Microsoft\Browser Sample Installer\BrowserSample.exe"
    

    يظهر مخرجات الأوامر.

    Microsoft (R) CLR Native Image Generator - Version 4.0.21102.0
    Copyright (c) Microsoft Corporation.  All rights reserved.
    
    NGEN Roots:
    
    C:\Program Files (x86)\Microsoft\Browser Sample Installer\BrowserSample.exe
    
    NGEN Roots that depend on "c:\Program Files (x86)\Microsoft\Browser Sample Installer\BrowserSample.exe":
    
    C:\Program Files (x86)\Microsoft\Browser Sample Installer\BrowserSample.exe
    
    Native Images:
    
    BrowserSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null <debug>
    

    ملاحظة

    إذا لم يعرض ngen.exe نسخة أصلية، يمكنك العثور على سجلات منشئ الصورة الأصلية في واحد الدلائل التالية:

    %SystemRoot%\Microsoft.NET\Framework64\v%SystemRoot%\Microsoft.NET\Framework\v < الإصدار CLR > < الإصدار CLR >

    الملف ngen.يسجل هو أحدث التسجيل لاستكشاف الأخطاء وإصلاحها.

راجع أيضًا:

المرجع

خاصية CustomActionData

Ngen.exe (مولد النسخة الأصلي)

المبادئ

عملية تنفيذ المدارة

موارد أخرى

إدارة الاجراءات مخصصة في توزيع