'Insert this line before invoking any ArcObjects to bind Engine runtime. ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop)
protected override void OnAfterInstall(IDictionary savedState) { base.OnAfterInstall(savedState); string regAsmPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles), "ArcGIS\\bin\\ESRIRegAsm.exe"); string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string args = "\"" + appPath + "\" /p:Desktop /s"; System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.FileName = regAsmPath; startInfo.Arguments = args; System.Diagnostics.Process.Start(startInfo); }
protected override void OnBeforeUninstall(IDictionary savedState) { base.OnBeforeUninstall(savedState); string regAsmPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles), "ArcGIS\\bin\\ESRIRegAsm.exe"); string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string args = "\"" + appPath + "\" /p:Desktop /u /s"; System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.FileName = regAsmPath; startInfo.Arguments = args; System.Diagnostics.Process.Start(startInfo); }
I chose the option to modify the project file to call esriRegAsm.exe instead of using the Add from File option.The project I migrated used a standard Visual Studio Deployment project to create the installer. I removed the code in the Installer class to register my classes with the ESRI component categories. I then added code to call esriRegAsm to perform the category component registration. This is the code I added to the OnAfterInstall event in the installer class:protected override void OnAfterInstall(IDictionary savedState) { base.OnAfterInstall(savedState); string regAsmPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles), "ArcGIS\\bin\\ESRIRegAsm.exe"); string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string args = "\"" + appPath + "\" /p:Desktop /s"; System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.FileName = regAsmPath; startInfo.Arguments = args; System.Diagnostics.Process.Start(startInfo); }This is the code I added to the OnBeforeUninstall event:protected override void OnBeforeUninstall(IDictionary savedState) { base.OnBeforeUninstall(savedState); string regAsmPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles), "ArcGIS\\bin\\ESRIRegAsm.exe"); string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string args = "\"" + appPath + "\" /p:Desktop /u /s"; System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.FileName = regAsmPath; startInfo.Arguments = args; System.Diagnostics.Process.Start(startInfo); }
That is correct, the old Install/Uninstall code is no longer needed. I commented out that code and added the code I posted earlier. I used the same Installer class so that I wouldn't have to add new Custom Actions for a new Installer class.
myBase.OnAfterInstall(savedState); Dim regAsmPath As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles), "ArcGIS\bin\ESRIRegAsm.exe") Dim appPath As String = System.Reflection.Assembly.GetExecutingAssembly().Location Dim args As String = """" & appPath & """ /p:Desktop /s" Dim startInfo As System.Diagnostics.ProcessStartInfo = new System.Diagnostics.ProcessStartInfo() startInfo.FileName = regAsmPath startInfo.Arguments = args System.Diagnostics.Process.Start(startInfo)
Yes, exclude all of the ESRI references. The code I posted is in C# and I don't have a VB.NET version. This is an untested conversion of the first routine: myBase.OnAfterInstall(savedState); Dim regAsmPath As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles), "ArcGIS\bin\ESRIRegAsm.exe") Dim appPath As String = System.Reflection.Assembly.GetExecutingAssembly().Location Dim args As String = """" & appPath & """ /p:Desktop /s" Dim startInfo As System.Diagnostics.ProcessStartInfo = new System.Diagnostics.ProcessStartInfo() startInfo.FileName = regAsmPath startInfo.Arguments = args System.Diagnostics.Process.Start(startInfo)
Imports System.ComponentModel Imports System.Configuration.Install Public Class Installer1 Public Sub New() MyBase.New() 'This call is required by the Component Designer. InitializeComponent() 'Add initialization code after the call to InitializeComponent. End Sub Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary) MyBase.Install(stateSaver) 'Register the custom component. '----------------------------- 'The default location of the ESRIRegAsm utility. 'Note how the whole string is embedded in quotes because of the spaces in the path. Dim cmd1 As String = """" + Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + "\ArcGIS\bin\ESRIRegAsm.exe" + """" 'Obtain the input argument (via the CustomActionData Property) in the setup project. 'An example CustomActionData property that is passed through might be something like: '/arg1="[ProgramFilesFolder]\[ProductName]\bin\ArcMapClassLibrary_Implements.dll", 'which translates to the following on a default install: 'C:\Program Files\MyGISApp\bin\ArcMapClassLibrary_Implements.dll. Dim part1 As String = Me.Context.Parameters.Item("arg1") 'Add the appropriate command line switches when invoking the ESRIRegAsm utility. 'In this case: /p:Desktop = means the ArcGIS Desktop product, /s = means a silent install. Dim part2 As String = " /p:Desktop /s" 'It is important to embed the part1 in quotes in case there are any spaces in the path. Dim cmd2 As String = """" + part1 + """" + part2 'Call the routing that will execute the ESRIRegAsm utility. Dim exitCode As Integer = ExecuteCommand(cmd1, cmd2, 10000) End Sub Public Overrides Sub Uninstall(ByVal savedState As System.Collections.IDictionary) MyBase.Uninstall(savedState) 'Unregister the custom component. '--------------------------------- 'The default location of the ESRIRegAsm utility. 'Note how the whole string is embedded in quotes because of the spaces in the path. Dim cmd1 As String = """" + Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + "\ArcGIS\bin\ESRIRegAsm.exe" + """" 'Obtain the input argument (via the CustomActionData Property) in the setup project. 'An example CustomActionData property that is passed through might be something like: '/arg1="[ProgramFilesFolder]\[ProductName]\bin\ArcMapClassLibrary_Implements.dll", 'which translates to the following on a default install: 'C:\Program Files\MyGISApp\bin\ArcMapClassLibrary_Implements.dll. Dim part1 As String = Me.Context.Parameters.Item("arg1") 'Add the appropriate command line switches when invoking the ESRIRegAsm utility. 'In this case: /p:Desktop = means the ArcGIS Desktop product, /u = means unregister the Custom Component, /s = means a silent install. Dim part2 As String = " /p:Desktop /u /s" 'It is important to embed the part1 in quotes in case there are any spaces in the path. Dim cmd2 As String = """" + part1 + """" + part2 'Call the routing that will execute the ESRIRegAsm utility. Dim exitCode As Integer = ExecuteCommand(cmd1, cmd2, 10000) End Sub Public Shared Function ExecuteCommand(ByVal Command1 As String, ByVal Command2 As String, ByVal Timeout As Integer) As Integer 'Set up a ProcessStartInfo using your path to the executable (Command1) and the command line arguments (Command2). Dim ProcessInfo As ProcessStartInfo = New ProcessStartInfo(Command1, Command2) ProcessInfo.CreateNoWindow = True ProcessInfo.UseShellExecute = False 'Invoke the process. Dim Process As Process = Process.Start(ProcessInfo) Process.WaitForExit(Timeout) 'Finish. Dim ExitCode As Integer = Process.ExitCode Process.Close() Return ExitCode End Function End Class
The solution in that link is pretty much the same thing as the code I posted except they're putting the installer class in its own project. They then add new custom actions to the installer project to call this installer class. I used the same installer class that I had been using just so that I wouldn't have to remove the old custom actions and add new ones (not that it would take any real effort to do so). The big difference between their solution and mine is how the installer class get the path to your assembly. In my code, I'm using the Reflection namespace to get the needed path. It's easy and it works. Their solution is getting the path through a property you have to set inside your installer project. This is what they're doing in the walkthrough when they are setting the CustomActionData property in the custom action properties dialog. If you use this solution, you'll have to change this so that it uses the location of the assembly you want to register. I haven't tried it but you'll probably need to change the value to something like this: /arg1="[TARGETDIR]\yourAssemblyName.dll". This is assuming you're installing the assembly directly to the target directory. Othewise you'll also have to append whatever subdirectory path you're installing to before the assembly filename.
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.