在.NET中,如何检测用户是否安装了特定的可再发行组件?

时间:2021-07-21 01:22:13

I have created a class which builds a Crystal report and displays it in a report viewer.

我创建了一个类来构建Crystal报表并将其显示在报表查看器中。

However, without the Crystal Redistributable, the code crashes. How can I programatically detect whether the end-user has the Crystal DLL installed?

但是,如果没有Crystal Redistributable,代码会崩溃。如何以编程方式检测最终用户是否安装了Crystal DLL?

The code I am required to include is:

我需要包含的代码是:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

5 个解决方案

#1


I suppose Crystal installs to GAC. So you need to programmatically browse Global assembly cache and look for Crystal assembly there

我想Crystal安装到GAC。因此,您需要以编程方式浏览全局程序集缓存并在那里查找Crystal程序集

GAC can be programmatically managed thru Windows API. Here you will find a simple wrapper that allows to manage GAC from a managed code

GAC可以通过Windows API以编程方式进行管理。在这里,您将找到一个简单的包装器,允许从托管代码管理GAC

But I would not recommend you to go this way. :)

但我不建议你这样走。 :)

The good solution is usually too check for all required assemblies during the installation of your software, I suppose Windows Installer has functions to check for assemblies

在安装软件期间,通常也会检查所有必需的程序集,我认为Windows Installer具有检查程序集的功能。

However, it is not always OK. Suppose if you would like users to run your program even without Crystal, but do not allow show reports if Crystal is not installed.

但是,并不总是好的。假设您希望用户在没有Crystal的情况下运行程序,但如果未安装Crystal,则不允许显示报告。

In this case you should decouple all Reports functionality from other forms. You should create a separate project with Crystal Reports functionality, let's call it MyReports. Only that project should reference to Crystal assemblies, while other should not. Other projects also should not directly reference to MyReports.

在这种情况下,您应该将所有报表功能与其他表单分离。您应该使用Crystal Reports功能创建一个单独的项目,我们称之为MyReports。只有那个项目应该引用Crystal程序集,而其他项不应该引用。其他项目也不应该直接引用MyReports。

And finally you should use reflection to call a report viewer that is implemented inside MyReports from other projects.

最后,您应该使用反射来调用从其他项目在MyReports中实现的报表查看器。

Usually you will write try / catch around the procedure where you will use reflection to load MyReports assembly from file. So, if Crystal or something else not exist, it will throw exception, you will display it to user, but the other parts of the program will work.

通常,您将在将使用反射从文件加载MyReports程序集的过程中编写try / catch。因此,如果Crystal或其他东西不存在,它将抛出异常,您将显示给用户,但程序的其他部分将起作用。

Also, you can read about Dependency Injection design pattern, it helps to manage such problems.

此外,您可以阅读有关依赖注入设计模式,它有助于管理此类问题。

#2


Ideally, you would take care of all of the dependencies of your application at install time and make sure that all the the required components are already installed. However you can wrap your code that makes calls to the DLLs in question in a try..catch block and catch the DllNotFoundException when it gets thrown.

理想情况下,您将在安装时处理应用程序的所有依赖项,并确保已安装所有必需的组件。但是,您可以在try..catch块中包装调用DLL的代码,并在抛出时捕获DllNotFoundException。

#3


You could check if the following registry key exists

您可以检查以下注册表项是否存在

HKEY_CURRENT_USER\Software\Crystal Decisions

This will tell you if crystal reports is installed. if you want to check a particular version check the child key. For instance the crystal reports installed with Visual Studio 2008 is 10.2

这将告诉您是否安装了水晶报告。如果要检查特定版本,请检查子键。例如,随Visual Studio 2008安装的水晶报表是10.2

#4


Use a merge module with your setup. Sap have a list here:

在您的设置中使用合并模块。 Sap有一个清单:

Merge modules

#5


You can find out these details by looking into the registry. I will search and provide an update.

您可以通过查看注册表找到这些详细信息。我将搜索并提供更新。

Edit: You could also include Crystal reports as a prerequisite in the deployment package. You can then be sure that the final user has the library.

编辑:您还可以将Crystal报表作为部署包中的先决条件。然后,您可以确保最终用户拥有该库。

#1


I suppose Crystal installs to GAC. So you need to programmatically browse Global assembly cache and look for Crystal assembly there

我想Crystal安装到GAC。因此,您需要以编程方式浏览全局程序集缓存并在那里查找Crystal程序集

GAC can be programmatically managed thru Windows API. Here you will find a simple wrapper that allows to manage GAC from a managed code

GAC可以通过Windows API以编程方式进行管理。在这里,您将找到一个简单的包装器,允许从托管代码管理GAC

But I would not recommend you to go this way. :)

但我不建议你这样走。 :)

The good solution is usually too check for all required assemblies during the installation of your software, I suppose Windows Installer has functions to check for assemblies

在安装软件期间,通常也会检查所有必需的程序集,我认为Windows Installer具有检查程序集的功能。

However, it is not always OK. Suppose if you would like users to run your program even without Crystal, but do not allow show reports if Crystal is not installed.

但是,并不总是好的。假设您希望用户在没有Crystal的情况下运行程序,但如果未安装Crystal,则不允许显示报告。

In this case you should decouple all Reports functionality from other forms. You should create a separate project with Crystal Reports functionality, let's call it MyReports. Only that project should reference to Crystal assemblies, while other should not. Other projects also should not directly reference to MyReports.

在这种情况下,您应该将所有报表功能与其他表单分离。您应该使用Crystal Reports功能创建一个单独的项目,我们称之为MyReports。只有那个项目应该引用Crystal程序集,而其他项不应该引用。其他项目也不应该直接引用MyReports。

And finally you should use reflection to call a report viewer that is implemented inside MyReports from other projects.

最后,您应该使用反射来调用从其他项目在MyReports中实现的报表查看器。

Usually you will write try / catch around the procedure where you will use reflection to load MyReports assembly from file. So, if Crystal or something else not exist, it will throw exception, you will display it to user, but the other parts of the program will work.

通常,您将在将使用反射从文件加载MyReports程序集的过程中编写try / catch。因此,如果Crystal或其他东西不存在,它将抛出异常,您将显示给用户,但程序的其他部分将起作用。

Also, you can read about Dependency Injection design pattern, it helps to manage such problems.

此外,您可以阅读有关依赖注入设计模式,它有助于管理此类问题。

#2


Ideally, you would take care of all of the dependencies of your application at install time and make sure that all the the required components are already installed. However you can wrap your code that makes calls to the DLLs in question in a try..catch block and catch the DllNotFoundException when it gets thrown.

理想情况下,您将在安装时处理应用程序的所有依赖项,并确保已安装所有必需的组件。但是,您可以在try..catch块中包装调用DLL的代码,并在抛出时捕获DllNotFoundException。

#3


You could check if the following registry key exists

您可以检查以下注册表项是否存在

HKEY_CURRENT_USER\Software\Crystal Decisions

This will tell you if crystal reports is installed. if you want to check a particular version check the child key. For instance the crystal reports installed with Visual Studio 2008 is 10.2

这将告诉您是否安装了水晶报告。如果要检查特定版本,请检查子键。例如,随Visual Studio 2008安装的水晶报表是10.2

#4


Use a merge module with your setup. Sap have a list here:

在您的设置中使用合并模块。 Sap有一个清单:

Merge modules

#5


You can find out these details by looking into the registry. I will search and provide an update.

您可以通过查看注册表找到这些详细信息。我将搜索并提供更新。

Edit: You could also include Crystal reports as a prerequisite in the deployment package. You can then be sure that the final user has the library.

编辑:您还可以将Crystal报表作为部署包中的先决条件。然后,您可以确保最终用户拥有该库。