Installing a Windows Service without Visual Studio's installutil.exe. Ask Question Asked 5 years, 9 months ago. Active 8 months ago. Viewed 15k times 2. In a few days I'll be installing a Windows Service I developed on my development machine (which ultimately hosts a WCF-over-SOAP service) on a staging machine. From StackOverflow: Install. I have a standard.NET windows service written in C#. Can it install itself without using InstallUtil? Should I use the service installer class?
-->Lo strumento Programma di installazione è un'utilità da riga di comando che consente di installare e disinstallare le risorse del server eseguendo i componenti del programma di installazione di assembly specificati.The Installer tool is a command-line utility that allows you to install and uninstall server resources by executing the installer components in specified assemblies.Questo strumento funziona insieme alle classi nello spazio dei nomi System.Configuration.Install.This tool works in conjunction with classes in the System.Configuration.Install namespace.
Viene installato automaticamente con Visual Studio.This tool is automatically installed with Visual Studio.Per eseguire lo strumento, usare il Prompt dei comandi per gli sviluppatori per Visual Studio (o il prompt dei comandi di Visual Studio in Windows 7).To run the tool, use the Developer Command Prompt for Visual Studio (or the Visual Studio Command Prompt in Windows 7).Per altre informazioni, vedere Prompt dei comandi.For more information, see Command Prompts.
Al prompt dei comandi digitare quanto segue:At the command prompt, type the following:
SintassiSyntax
ParametriParameters
ArgomentoArgument | DescrizioneDescription |
---|---|
assembly | Nome file dell'assembly in cui eseguire i componenti del programma di installazione.The file name of the assembly in which to execute the installer components.Omettere questo parametro se si desidera specificare il nome sicuro dell'assembly utilizzando l'opzione /AssemblyName .Omit this parameter if you want to specify the assembly's strong name by using the /AssemblyName option. |
OpzioniOptions
OpzioneOption | DescrizioneDescription |
---|---|
/h[elp] oppure-or- /? | Visualizza la sintassi e le opzioni di comando dello strumento.Displays command syntax and options for the tool. |
/help assembly/help assemblyoppure-or- /? assembly/? assembly | Visualizza le opzioni aggiuntive riconosciute dai singoli programmi di installazione all'interno dell'assembly specificato, insieme alla sintassi e alle opzioni di comando di InstallUtil.exe.Displays additional options recognized by individual installers within the specified assembly, along with command syntax and options for InstallUtil.exe.Questa opzione aggiunge il testo restituito dalla proprietà Installer.HelpText di ogni componente del programma di installazione al testo della Guida di InstallUtil.exe.This option adds the text returned by each installer component's Installer.HelpText property to the help text of InstallUtil.exe. |
/AssemblyName 'assemblyName/AssemblyName 'assemblyName,Version=major.minor.build.revision,Version=major.minor.build.revision ,Culture=locale,Culture=locale ,PublicKeyToken=publicKeyToken',PublicKeyToken=publicKeyToken' | Specifica il nome sicuro di un assembly, che verrà registrato nella Global Assembly Cache.Specifies the strong name of an assembly, which must be registered in the global assembly cache.Il nome dell'assembly deve essere completo, con versione, impostazioni cultura e token di chiave pubblica.The assembly name must be fully qualified with the version, culture, and public key token of the assembly.Il nome completo deve essere racchiuso tra virgolette.The fully qualified name must be surrounded by quotes. Ad esempio, 'myAssembly, Culture=neutral, PublicKeyToken=0038abc9deabfle5, Version=4.0.0.0' è un nome di assembly completo.For example, 'myAssembly, Culture=neutral, PublicKeyToken=0038abc9deabfle5, Version=4.0.0.0' is a fully qualified assembly name. |
/InstallStateDir=[ directoryName] /InstallStateDir=[ directoryName] | Specifica la directory del file con estensione InstallState contenente i dati utilizzati per la disinstallazione dell'assembly.Specifies the directory of the .InstallState file that contains the data used to uninstall the assembly.La directory predefinita è quella che contiene l'assembly.The default is the directory that contains the assembly. |
/LogFile= [filename]/LogFile= [filename] | Specifica il nome del file di log in cui è registrato lo stato dell'installazione.Specifies the name of the log file where installation progress is recorded.Per impostazione predefinita, se l'opzione /LogFile viene omessa, viene creato un file di log denominato assemblyname.InstallLog.By default, if the /LogFile option is omitted, a log file named assemblyname.InstallLog is created.Se filename viene omesso, non verrà generato alcun file di log.If filename is omitted, no log file is generated. |
/LogToConsole ={true |false }/LogToConsole ={true |false } | Se true , visualizza l'output sulla console.If true , displays output to the console.Se false (impostazione predefinita), evita la visualizzazione dell'output sulla console.If false (the default), suppresses output to the console. |
/ShowCallStack | Restituisce lo stack di chiamate al file di log se si verifica un'eccezione durante l'installazione.Outputs the call stack to the log file if an exception occurs at any point during installation. |
/u [ninstall ]/u [ninstall ] | Disinstalla gli assembly specificati.Uninstalls the specified assemblies.A differenza delle altre opzioni, /u si applica a tutti gli assembly, indipendentemente dalla posizione dell'opzione nella riga di comando.Unlike the other options, /u applies to all assemblies regardless of where the option appears on the command line. |
Opzioni aggiuntive del programma di installazioneAdditional Installer Options
I singoli programmi di installazione usati all'interno di un assembly sono in grado di riconoscere opzioni oltre a quelle elencate nella sezione Opzioni.Individual installers used within an assembly may recognize options in addition to those listed in the Options section.Per ulteriori informazioni su queste opzioni, eseguire InstallUtil.exe con i percorsi degli assembly sulla riga di comando con l'opzione
/?
o /help
.To learn about these options, run InstallUtil.exe with the paths of the assemblies on the command line along with the /?
or /help
option.Per specificare queste opzioni, includerle nella riga di comando con le opzioni riconosciute da InstallUtil.exe.To specify these options, you include them on the command line along with the options recognized by InstallUtil.exe.Nota
![Name Name](http://gigi.nullneuron.net/gigilabs/wp-content/uploads/2015/08/bitness-badimageformatexception.png)
Il testo della Guida sulle opzioni supportate da singoli componenti del programma di installazione viene restituito dalla proprietà Installer.HelpText.Help text on the options supported by individual installer components is returned by the Installer.HelpText property.Le singole opzioni che sono state inserite nella riga di comando sono accessibili a livello di codice dalla proprietà Installer.Context.The individual options that have been entered on the command line are accessible programmatically from the Installer.Context property.
Tutte le opzioni e i parametri della riga di comando vengono scritti nel file di log dell'installazione.All options and command-line parameters are written to the installation log file.Tuttavia, se si utilizza il parametro
/Password
, che è riconosciuto da alcuni componenti del programma di installazione, le informazioni relative alla password verranno sostituite da otto asterischi (*) e non verranno visualizzate nel file di log.However, if you use the /Password
parameter, which is recognized by some installer components, the password information will be replaced by eight asterisks (*) and will not appear in the log file.Importante
In alcuni casi, i parametri passati al programma di installazione possono includere informazioni riservate o personali che, per impostazione predefinita, vengono scritte in un file di log di testo normale.In some cases, parameters passed to the installer may include sensitive or personally identifiable information, which, by default, is written to a plain text log file.Per evitare questo comportamento, è possibile eliminare il file di log specificando
/LogFile=
(senza l'argomento filename) dopo Installutil.exe nella riga di comando.To prevent this behavior, you can suppress the log file by specifying /LogFile=
(with no filename argument) after Installutil.exe on the command line.NoteRemarks
Le applicazioni .NET Framework sono costituite da file di programma tradizionali e risorse associate, quali code di messaggi, log eventi e contatori delle prestazioni, che è necessario creare quando l'applicazione viene distribuita..NET Framework applications consist of traditional program files and associated resources, such as message queues, event logs, and performance counters that must be created when the application is deployed.È possibile utilizzare i componenti del programma di installazione di un assembly per creare queste risorse quando l'applicazione viene installata e rimuoverle quando l'applicazione viene disinstallata.You can use an assembly's installer components to create these resources when your application is installed and to remove them when your application is uninstalled.Installutil.exe rileva ed esegue questi componenti del programma di installazione.Installutil.exe detects and executes these installer components.
È possibile specificare più assembly nella stessa riga di comando.You can specify multiple assemblies on the same command line.Qualsiasi opzione specificata prima del nome di un assembly ha effetto sull'installazione di tale assembly.Any option that occurs before an assembly name applies to that assembly's installation.Fatta eccezione per
/u
e /AssemblyName
, le opzioni sono cumulative ma sottoponibili a override.Except for /u
and /AssemblyName
, options are cumulative but overridable.In altre parole, le opzioni specificate per un assembly vengono applicate a tutti gli assembly successivi a meno che l'opzione non venga specificata con un nuovo valore.That is, options specified for one assembly apply to all subsequent assemblies unless the option is specified with a new value.Se si esegue Installutil.exe su un assembly senza specificare alcuna opzione, i tre file seguenti verranno inseriti nella directory dell'assembly:If you run Installutil.exe against an assembly without specifying any options, it places the following three files into the assembly's directory:
- InstallUtil.InstallLog - Contiene una descrizione generale dello stato dell'installazione.InstallUtil.InstallLog - Contains a general description of the installation progress.
- assemblyname.InstallLog: contiene informazioni specifiche della fase di commit del processo di installazione.assemblyname.InstallLog - Contains information specific to the commit phase of the installation process.Per ulteriori informazioni sulla fase di commit, vedere il metodo Commit.For more information about the commit phase, see the Commit method.
- assemblyname.InstallState: contiene i dati usati per disinstallare l'assembly.assemblyname.InstallState - Contains data used to uninstall the assembly.
Installutil.exe utilizza la reflection per esaminare gli assembly specificati e individuare tutti i tipi Installer il cui attributo System.ComponentModel.RunInstallerAttribute è impostato su
true
.Installutil.exe uses reflection to inspect the specified assemblies and to find all Installer types that have the System.ComponentModel.RunInstallerAttribute attribute set to true
.Lo strumento esegue quindi il metodo Installer.Install o Installer.Uninstall su ciascuna istanza del tipo Installer.The tool then executes either the Installer.Install or the Installer.Uninstall method on each instance of the Installer type.Installutil.exe esegue l'installazione in modo transazionale: se risulta impossibile installare uno degli assembly, viene eseguito il rollback dell'installazione di tutti gli altri assembly.Installutil.exe performs installation in a transactional manner; that is, if one of the assemblies fails to install, it rolls back the installations of all other assemblies.La disinstallazione non è invece transazionale.Uninstall is not transactional.Installutil.exe può installare o disinstallare assembly con nome sicuro, ma non assembly con firma ritardata.Installutil.exe cannot install or uninstall delay-signed assemblies, but it can install or uninstall strong-named assemblies.
A partire da .NET Framework versione 2.0, la versione a 32 bit di Common Language Runtime (CLR) viene fornita solo con la versione a 32 bit dello strumento Programma di installazione, mentre la versione a 64 bit di CLR viene fornita con le versioni a 32 bit e a 64 bit di questo strumento.Starting with the .NET Framework version 2.0, the 32-bit version of the common language runtime (CLR) ships with only the 32-bit version of the Installer tool, but the 64-bit version of the CLR ships with both 32-bit and 64-bit versions of the Installer tool.Se si utilizza CLR a 64 bit, occorre utilizzare lo strumento Programma di installazione a 32 bit per installare assembly a 32 bit e quello a 64 bit per installare assembly a 64 bit e MSIL (Microsoft Intermediate Language).When using the 64-bit CLR, use the 32-bit Installer tool to install 32-bit assemblies, and the 64-bit Installer tool to install 64-bit and Microsoft intermediate language (MSIL) assemblies.Il funzionamento delle due versioni dello strumento Programma di installazione è identico.Both versions of the Installer tool behave the same.
Non è possibile utilizzare Installutil.exe per distribuire un servizio di Windows creato utilizzando C++ perché Installutil.exe non è in grado di riconoscere il codice nativo incorporato generato dal compilatore C++.You cannot use Installutil.exe to deploy a Windows service that was created by using C++, because Installutil.exe cannot recognize the embedded native code that is produced by the C++ compiler.Se si tenta di distribuire un servizio di Windows C++ con Installutil.exe, verrà generata un'eccezione quale BadImageFormatException.If you try to deploy a C++ Windows service with Installutil.exe, an exception such as BadImageFormatException will be thrown.Per operare con questo scenario, spostare il codice del servizio in un modulo C++, quindi scrivere l'oggetto del programma di installazione in C# o in Visual Basic.To work with this scenario, move the service code to a C++ module, and then write the installer object in C# or Visual Basic.
EsempiExamples
Il comando che segue visualizza una descrizione della sintassi e delle opzioni di comando per InstallUtil.exe.The following command displays a description of the command syntax and options for InstallUtil.exe.
Il comando che segue visualizza una descrizione della sintassi e delle opzioni di comando per InstallUtil.exe.The following command displays a description of the command syntax and options for InstallUtil.exe.Visualizza anche una descrizione e un elenco delle opzioni supportate dai componenti del programma di installazione in
myAssembly.exe
se il testo della Guida è stato assegnato alla proprietà Installer.HelpText del programma di installazione.It also displays a description and list of options supported by the installer components in myAssembly.exe
if help text has been assigned to the installer's Installer.HelpText property.Il comando che segue esegue i componenti del programma di installazione nell'assembly
myAssembly.exe
.The following command executes the installer components in the assembly myAssembly.exe
.Il comando che segue esegue i componenti del programma di installazione in un assembly utilizzando l'opzione
/AssemblyName
e un nome completo.The following command executes the installer components in an assembly by using the /AssemblyName
switch and a fully qualified name.Il comando che segue esegue i componenti del programma di installazione in un assembly specificato in base al nome file e in un assembly specificato in base al nome sicuro.The following command executes the installer components in an assembly specified by file name and in an assembly specified by strong name.Si noti che tutti gli assembly specificati in base al nome file devono precedere gli assembly specificati in base al nome sicuro nella riga di comando, poiché l'opzione
/AssemblyName
non può essere sottoposta a override.Note that all assemblies specified by file name must precede assemblies specified by strong name on the command line, because the /AssemblyName
option cannot be overridden.Il comando che segue esegue i componenti del programma di disinstallazione nell'assembly
myAssembly.exe
.The following command executes the uninstaller components in the assembly myAssembly.exe
.Il comando seguente esegue i componenti del programma di disinstallazione negli assembly
myAssembly1.exe
e myAssembly2.exe
.The following command executes the uninstaller components in the assemblies myAssembly1.exe
and myAssembly2.exe
.Poiché la posizione dell'opzione
/u
nella riga di comando non è importante, questo è equivalente al comando seguente.Because the position of the /u
option on the command line is not important, this is equivalent to the following command.Il comando che segue esegue i programmi di installazione nell'assembly
myAssembly.exe
e specifica che le informazioni sullo stato verranno scritte in myLog.InstallLog
.The following command executes the installers in the assembly myAssembly.exe
and specifies that progress information will be written to myLog.InstallLog
.Il comando che segue esegue i programmi di installazione contenuti nell'assembly
myAssembly.exe
, specifica che le informazioni sullo stato di avanzamento devono essere scritte in myLog.InstallLog
e utilizza l'opzione /reg
personalizzata dei programmi di installazione per specificare che è necessario aggiornare il Registro di sistema.The following command executes the installers in the assembly myAssembly.exe
, specifies that progress information should be written to myLog.InstallLog
, and uses the installers' custom /reg
option to specify that updates should be made to the system registry.Il comando seguente esegue i programmi di installazione contenuti nell'assembly
myAssembly.exe
, usa l'opzione /email
personalizzata del programma di installazione per specificare l'indirizzo di posta elettronica dell'utente ed elimina l'output nel file di log.The following command executes the installers in the assembly myAssembly.exe
, uses the installer's custom /email
option to specify the user's email address, and suppresses output to the log file.Il comando che segue scrive lo stato dell'installazione di
myAssembly.exe
in myLog.InstallLog
e quello di myTestAssembly.exe
in myTestLog.InstallLog
.The following command writes the installation progress for myAssembly.exe
to myLog.InstallLog
and writes the progress for myTestAssembly.exe
to myTestLog.InstallLog
.