需要解决方法:通知用户 exe 缺少应用程序内的依赖项?

发布于 2024-10-16 02:56:28 字数 273 浏览 6 评论 0原文

我编写了一个使用 SharePoint dll 文件的快速控制台应用程序。如果我尝试在没有上述 dll 文件的计算机上运行它,应用程序在打开时会立即崩溃。

我绝对是一个新手,但我希望应用程序能够在严重崩溃之前告诉用户他们在错误的机器上使用它。除了编写第二个应用程序来扫描依赖项并在相关应用程序之前运行之外,还有其他方法可以做到这一点吗?如果我将需要依赖项的代码放在一个单独的类中,并且在应用程序检查它位于正确的计算机上之前不会实例化该代码,那么应用程序在打开时是否仍会立即失败?肯定有人已经找到了解决这种情况的方法。

I wrote a quick console application that uses SharePoint dll files. If I attempt to run it on a machine that doesn't have said dll files, the application immediately crashes upon opening.

I'm definitely a newbie, but I would prefer if there was a way the application could tell the user they are using it on a wrong machine, before it hard crashed. Is there a way of doing this other than writing a second application to scan for dependencies, to be run prior to the application in question? If I put the code that needs dependencies in a separate class, that isn't instantiated until the application has checked it is on the correct computer, will the application still fail immediately on opening? Surely someone has figured out a workaround for this sort of situation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小…楫夜泊 2024-10-23 02:56:28

不幸的是,您必须编写一个启动器应用程序 - 如果您考虑一下,主应用程序甚至需要启动所需的 DLL。如果将扫描嵌入到主应用程序中,则由于缺少 DLL,扫描将无法启动。

您也许可以使用插件架构来扫描所需的 DLL 并动态加载它们(MEF 浮现在脑海中) 。

Unfortunately you will have to write a launcher application - if you think about it, the required DLLs need to be there for the main application to even start. If you embed the scan in your main application, it will not start due to the missing DLLs.

You may be able to use a plugin architecture that scans for required DLLs and loads them dynamically (MEF comes to mind).

瑕疵 2024-10-23 02:56:28

如何将该 dll 的加载包装到:

 try { 
      Assembly.Load(..);
 }
 catch(TypeLoadException ex) {

         //Let the user know which type from what dll was not loaded.
 }

不过,您必须在运行时加载该 dll 才能实际执行此操作。

How about wrapping the load of that dll into:

 try { 
      Assembly.Load(..);
 }
 catch(TypeLoadException ex) {

         //Let the user know which type from what dll was not loaded.
 }

You will have to load that dll at runtime to actually do that though.

泪是无色的血 2024-10-23 02:56:28

可以将程序集复制到共享点的输出目录。所以参考是本地的。

It might be possible to copy the assemblies to the output directory for sharepoint. So references are made locally.

夜光 2024-10-23 02:56:28

如果您的应用程序直接引用 SharePoint dll 或程序集,则无法通知用户,因为如果任何静态链接的所需程序集不可用,.NET CLR 将不会执行您的代码。

您可以使用某种 SharePoint 程序集和类型的动态加载,以便在启动时应用程序不需要执行该程序集,或者您为应用程序创建一个启动器来执行检查,如果一切正常则启动您的应用程序否则通知用户。

if your application references directly the SharePoint dlls or assemblies there is no way to notify the user because the .NET CLR will not execute your code if any of the statically linked needed assemblies is not available.

you can either use some kind of dynamic loading of the SharePoint assembly and types so at the startup time the application does not need that assembly to execute, or you create a launcher for your application which does the check and if all is ok starts your application otherwise notifies the user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文