如何在构建时将我的 class 库程序集复制到我的 Web 项目?

How do I copy my class library assemblies to my Web project at build time?

问题
如何在构建时将我的 class 库程序集复制到我的 Core Mvc 项目?

问题陈述
我正在努力将 Onion Architecture 项目移植到 Asp.Net Core。本着设计思路,我有以下几点:

Some.Bootstrapper
- Startup.cs
Some.WebApi
- Program.cs

在 Program.cs 中,我正在引用 Bootstrapper 程序集来调用我的 Starup.cs 文件:

.UseStartup("Some.Bootstrapper")

但是,我不知道如何将 Bootstrapper 程序集文件输出到我的 WebApi 项目。 According to Onion, I should not be making a direct reference to Some.Bootstrapper from Some.WebApi. In my previous Asp.Net project, I used the properties window of my Bootstrapper project to set the output path (e.g: ..\Some.WebApi\bin\". However, in Asp.Net Core, I understand that I won't be able to set the output path until we move to msbuild. It seems this guy已经可以剥猫皮了。我不太确定如何。

预期行为
我应该能够调用 .UseStartup("Some.Bootstrapper") 而无需直接引用程序集。

感谢反馈。

您可以使用 System.Reflection.Assembly 命名空间

Assembly assembly = Assembly.LoadFrom("MyNice.dll");

Type type = assembly.GetType("MyType");

object instanceOfMyType = Activator.CreateInstance(type);

最终,在我的 Bootstrapper 项目中使用 post-compile 脚本将我的 DLL 复制到 WebApi 是对我来说最好的解决方案。

"scripts": {
    "postcompile": [ 
      "xcopy /I /F /Y %compile:OutputDir%\. ..\Some.WebApi\bin\%compile:Configuration%\netcoreapp1.0\" ]
  }

功劳归于 this thread

中的 Binoy