الإرشادات التفصيلية: لاستخدام Cusإلىm إجراء إلى ترجمة التعليمات برمجية ثنائية إلى الأصلي عند تثبيت
يمكنك تعريف الاجراءات cusإلىm إلى تحديد الأوامر التي يتم تشغيلها بعد تثبيت. على سبيل المثال، في هذه معاينة، يمكنك تحديد إجراء مخصص و تمرير اسم مسار EXE إلى CustomActionData خاصية التحويل البرمجي للملف التنفيذي للتعليمات البرمجية الأصلية بعد تثبيت تطبيق.
ملاحظة
قد يعرض جهاز الكمبيوتر الخاص بك أسماء أو مواقع مختلفة لبعض عناصر واجهة مستخدم Visual Studio في الإرشادات التالية. يحدد كل من إصدار Visual Studio لديك والإعدادات المستخدمة هذه العناصر. لمزيد من المعلومات، راجع العمل مع إعدادات.
إلى إنشاء تطبيق ويب مستعرض إلى نشر
من القائمة File (ملف)، أشر إلى New (جديد)، ثم انقر فوق Project (مشروع).
انقر فوق تطبيق Windows Forms.
بالنسبة الاسم، اكتب BrowserSample، و ثم انقر فوق موافق .
في القائمة عرض، انقر فوق تفاصيل.
توسيع الجميع أشكال Windows، ثم قم بسحب لوحة عنصر تحكم إلى الأعلى اليسار في النموذج.
في "مصمم النموذج"، اسحب مربع النص عنصر تحكم و زر عنصر تحكم إلى لوحة عنصر تحكم.
في "مصمم النموذج"، اسحب من متصفح ويب عنصر تحكم أدناه لوحة.
توسيع الحجم نموذج لاحتواء الجميع عناصر التحكم.
في "مصمم النموذج"، انقر فوق لوحة عنصر تحكم.
In the Properties Window, change the Dock property under Layout to Top.
في "مصمم النموذج"، انقر فوق عنصر التحكم متصفح ويب .
In the Properties Window, change the Dock property under Layout to Fill.
في the نموذج مصمم, انقر the زر عنصر تحكم.
In the Properties Window, change the Text property under Appearance to Go.
تغيير الحجم the نموذج, لوحة, مربع نص, زر, و متصفح ويب إلى your preferences.
في the نموذج مصمم, ينقر مزودجا the انتقال زر.
The عرض تعليمات برمجية for the Form1 رمز الملف appears.
إضافة 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); }
إلى اختبار the مستعرض, ضغط F5.
The نموذج opens.
في the صندوق نص, نوع https://www.microsoft.com, و then انقر انتقال.
The Microsoft ويب موقع appears.
إلى إنشاء the مخصص إجراء فئة
في قائمة ملف ، أشر إلى إضافة، و ثم انقر فوق مشروع جديد.
في the إضافة جديد مشروع حوار صندوق, انقر Windows, و then انقر فئة مكتبة.
في the اسم صندوق, نوع NGenCustomAction, و then انقر موافق.
في مشروع قائمة ، انقر فوق إضافة عنصر جديد .
في إضافة عنصر جديد? صندوق حوار انقر فوق عاموثم انقر فوق فئة مثبت. في الاسم صندوق اكتب من NGenCustomActionوثم انقر فوق إضافة.
في من مستكشف الحلول، قم بحذف Class1تعليمات برمجية ملف في مشروع NGenCustomAction.
إلى إضافة التعليمة البرمجية إلى إجراء مخصص
انقر نقراً مزدوجاً فوق رمز NGenCustomAction ملف في مستكشف الحلول (أو سطح التصميم)، ثم انقر فوق عرض تعليمات برمجية لفتح محرر تعليمات برمجية. إضافة التعليمة البرمجية التالية إلى أعلى وحدة نمطية?.
Imports System.IO Imports System.Diagnostics
using System.IO; using System.Diagnostics;
قم بتحديث إعلان فئة إلى يورث System.Configuration.Install.Installerclass.
Inherits System.Configuration.Install.Installer
: System.Configuration.Install.Installer
في التعليمة البرمجية 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); } } }
في التعليمة البرمجية 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"); }
إلى إضافة مشروع نشر الخاص بتطبيق "نماذج مستعرض"
في قائمة ملف ، أشر إلى إضافة، و ثم انقر فوق مشروع جديد.
في إضافة مشروع جديد صندوق حوار توسيع أنواع غير ذلك من المشروع، قم بتوسيع مشاريع الإعداد والنشر، انقر فوق مثبت Studio Visual Basicوثم انقر فوق إعداد مشروع.
في المربع الاسم ، اكتب من مستعرض نموذج مثبت، ومن ثم انقر فوق موافق .
في محرر ملف النظام، تحديد مجلد التطبيقات. تشغيل theActiتشغيل قائمة, انقر إضافة.
مجموعة إخراج المشروع إضافة صندوق حوار تظهر.
في صندوق التحرير والسرد المنسدلة مشروع, تحديد BrowserSample انقر فوق إخراج مشروع وثم انقر فوق موافق .
في محرر ملف النظام، تحديد مجلد التطبيقات. تشغيل theActiتشغيل قائمة, انقر إضافة.
مجموعة إخراج المشروع إضافة صندوق حوار تظهر.
في المنسدلة مشروع المنسدلة صندوق التحرير والسرد، تحديد NGenCustomAction، وانقر فوق إخراج مشروع، و ثم انقر فوق موافق .
لإضافة NGEN إجراء مخصص إلى مشروع الإعداد
في من مستكشف الحلول، انقر فوق مشروع مستعرض نموذج مثبت.
في قائمة عرض ، أشر إلى محرر، و ثم انقر فوق الاجراءات مخصصة.
في محرر الاجراءات مخصصة، تحديد الاجراءات مخصصة عقدة.
في قائمة إجراء ، انقر فوق إضافة إجراء مخصص .
في صندوق الحوار تحديد عنصر في مشروع ، انقر نقراً مزدوجاً فوق مجلد التطبيقات، انقر فوق الإخراج الأساسي من NGenCustomAction (نشط) ، ثم انقر فوق موافق
تتم تمت الإضافة "إجراء مخصص في" منشئ الصورة الأصلية "إلى الجميع العقد الإجراء المخصص الرابع.
في العقدة يثّبت ، انقر فوق إخراج أساسي من NGenCustomAction (نشط).
في الإطار خصائص ، تغيير CusإلىmActionData خاصية إلى /Args="[دليل الهدف]BrowserSample.exe". قم بتضمين علامات الاقتباس.
ملاحظة
خاصية [دليل الهدف] هو الموقع تثبيت تنفيذي. يستخدم إجراء المخصص ngen.exe لتحويل المثبتة في تنفيذي إلى نسخة أصلية.
في من مستكشف الحل، انقر فوق من مستعرض نموذج مثبت إعداد مشروع.
من قائمة بنية ، انقر فوق إنشاء مثبت نماذج مستعرض.
للتحقق من تعليمة برمجية أصلية الجيل
انتقل إلى مجلد التثبيت والعثور BrowserSample.exe ملف. ل مثال%PROGRAMFILES%\CompanyName\Brower مثبت\BrowserSample.exe نموذج.
في تعجيل أوامر 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.يسجل هو أحدث التسجيل لاستكشاف الأخطاء وإصلاحها.