RE: VS2005 setup project: execute tasks without installing files?



Thanks for Phil's great answer.

Hi dpomt,

After going deep by the direction pointed by Phil, we have found a easier
solution for you. It is to write a C++ DLL and make it to be exclude in
your installer project which can dirrectly call managed methods. Following
is the detailed steps:

Prerequisites:
Windows Installer SDK must be installed. It can be downloaded at
http://www.microsoft.com/downloads/details.aspx?familyid=e96f8abc-62c3-4cc3-
93ad-bfc98e3ae4a3&displaylang=en.

1. Create a C++ DLL project named "CustomAction" and set it with Common
Language Runtime Support (/clr)
2. In project properties -> Linker -> Input -> Additional Dependencies ->
C:\MsiIntel.SDK\Lib\Msi.lib
3. In stdafx.h, add following includes
-----------------------------------------
#include <msi.h>
#include "msiquery.h"
-----------------------------------------
4. In CustomAction.cpp file, copy the code below:
-----------------------------------------
#include "StdAfx.h"

#using <mscorlib.dll>
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Reflection;

using namespace System::Runtime::InteropServices;

UINT __stdcall Install(MSIHANDLE hInstall)
{
WCHAR srcDirBuffer [500] = {0};
DWORD len = 500;
MsiGetPropertyW(hInstall, L"CustomActionData", srcDirBuffer, &len);

String^ s = gcnew String(srcDirBuffer);
String^ dllPath = s + "myddl1.dll";
MessageBox::Show(dllPath);
Assembly^ assembly = Assembly::LoadFrom(dllPath);
RegistrationServices^ service = gcnew RegistrationServices();
service->RegisterAssembly(assembly, AssemblyRegistrationFlags::None);

return 0;
}
-----------------------------------------
5. Add one def file with following content:
-----------------------------------------
LIBRARY "CustomAction"

EXPORTS
Install @1
-----------------------------------------
6. Compile into CustomAction.DLL
7. In Visual Studio Deployment project, add assembly and select
CustomAction.DLL.
8. In the assembly file's properties, set its property "Exclude" to true,
that will prevent it to be copied to user's machine.
9. Add it into Custom Action, in the Custom Action Editor, open its
properties, set its properties as following:
CustomActionData=[SourceDir]
EntryPoint=Install
InstallerClass=False
10. Build and run the installer.

The basic concept of this sample is that we pass the source dir into the
C++ custom action and we use it to get the dll path, then we invoke manged
code: RegistrationServices.RegisterAssembly to register the DLL. The sample
only implements one of your requirements, for the other one (add codegroup)
can be implemented as the same way.

Please follow the instruction above and let me know if you have any problem
when implementing it. In the meanwhile, please feel free to send email to
me if you want the sample project source code. I will be more than happy to
help you. My email address is hongyes@xxxxxxxxxxxxxxxxxxxx, remove
'online.'. I will be waiting for you reply or email.

Thanks again for Phil's insightful suggestion on this issue.

Have a nice day.

Regards,
Hongye Sun (hongyes@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx
 
This posting is provided "AS IS" with no warranties, and confers no rights.



.



Relevant Pages

  • Re: Custom Action dll installed with App
    ... What kind of Dll is this? ... Installer classes requires the assembly to be installed. ... > I added a dll to perform a custom action during the setup process. ...
    (microsoft.public.dotnet.framework.setup)
  • Rich Edit DLL hell (long)
    ... MS installer - what a crock! ... yet all other versions of Windows support at least V2, ... I suspect that the app. ... is supported by the DLL. ...
    (borland.public.delphi.nativeapi)
  • Re: Custom Actions during setup
    ... The reason being is I include the installer for SQLExpress in my setup ... Is the "executable" you mentioned a custom exe program you used(as custom ... You can also add a custom action class which use Process. ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.vsnet.setup)
  • RE: system.badimageformatexception returned from custom installer
    ... which references the dll that contains the custom installer code. ... Would you please provide more detailed information about your custom ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework)
  • Re: Custom Action dll installed with App
    ... If it's a C++ custom action Dll you can set its ... > assemblies, and the infrastructure to load and instantiate class methods ... > in Installer classes requires the assembly to be installed. ... >> I added a dll to perform a custom action during the setup process. ...
    (microsoft.public.dotnet.framework.setup)

Loading