首页 > 解决方案 > 是否可以将 nuget 包添加为仅运行时依赖项?

问题描述

我正在处理以下项目:

MyCustomerApp.csproj 是“可运行”项目,其工作方式如下:

  1. MyLauncher.exe 从 MyLauncher 项目复制到 MyCustomerApp 的输出
  2. 运行 MyLauncher.exe 时,它Assembly.Load(..)​​用于加载 MyCystomerApp.dll

有一个具体的原因说明为什么我们有这个我不会涉及的机制 - 现在认为它超出了范围。

现在问题来了;MyLauncherDependency 是 MyLauncher 的依赖项,但不是 MyCustomerApp 的依赖项。因此 MyLauncherDependency 不是 MyCustomerApp 的编译时依赖项 - 但它是运行时依赖项 - 因为它在运行时需要 MyLauncherDependency.dll。

我不想将 MyLauncherDependency.nupkg 添加到 MyCustomerApp,因为我不想让工程师从 MyCustomerApp 中的 MyLauncherDependency 访问类。

所以我的问题是:如何将 MyLauncherDependency.nupkg(或 MyLauncherDependency.nupkg)添加到 MyCustomerApp 作为仅运行时依赖项?

标签: c#dllnuget-package

解决方案


你必须使用Nuget吗?

MEF(托管扩展框架)非常适合在运行时加载插件。

https://docs.microsoft.com/en-us/dotnet/framework/mef/


推荐阅读