[英]Automatically copy related DLLs without binary reference
Visual Studio 2015, C# Console project + C# Library projects: Visual Studio 2015,C# 控制台项目 + C# 库项目:
Is there a way to achieve automatically copying related project binary output to an output dir of a particular "master" project without using Project reference (and Copy local = True)?有没有办法在不使用项目引用(和 Copy local = True)的情况下自动将相关项目二进制输出复制到特定“主”项目的输出目录?
I want to be able to maintain the exe-s and dll-s loosely coupled without the actual binary reference, but can rely on the related dll-s are always copied to the right output dir (eg Debug/Release).我希望能够在没有实际二进制引用的情况下保持 exe-s 和 dll-s 松散耦合,但可以依赖相关的 dll-s 始终复制到正确的输出目录(例如调试/发布)。
Example:例子:
I have only verified this solution on VS2017, but based on the date of the referenced MSDn article, it should work with VS2015 : use ReferenceOutputAssembly
is your csproj.我只在 VS2017 上验证了这个解决方案,但根据引用的 MSDn 文章的日期,它应该适用于 VS2015:使用
ReferenceOutputAssembly
是你的 csproj。 Sadly, this is a property that can only be added via manual edit of the csproj.遗憾的是,这是一个只能通过手动编辑 csproj 添加的属性。
<ProjectReference Include="..\..\Calfitec\PglLibPAC\PglOdpm\PglOdpm.csproj">
<Project>{261de855-9e8f-45de-b57d-fd4c7deb5f1b}</Project>
<Name>PglOdpm</Name>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
See also: How to have a Project Reference without referencing the actual binary另请参阅: 如何在不引用实际二进制文件的情况下拥有项目参考
This is the intended use of the feature:这是该功能的预期用途:
Sometimes you want a project reference from project B to project A to indicate a build-time dependency, but you don't actually want assembly B to reference assembly A (maybe because it's a runtime-only dependency or loaded using reflection).
有时您希望从项目 B 到项目 A 的项目引用来指示构建时依赖项,但您实际上并不希望程序集 B 引用程序集 A(可能因为它是仅运行时依赖项或使用反射加载)。
TL; TL; DR;
博士; The fact that
Copy local
even appears tells me that Console has a direct Add Reference dependency which kinda defeats the purpose of DI. Copy local
甚至出现的事实告诉我,Console 有一个直接的 Add Reference 依赖项,这有点违背了 DI 的目的。 Just let Visual Studio do it's thing via Copy Local=true
.只需让 Visual Studio 通过
Copy Local=true
来做这件事。
If:如果:
...then you should just let Visual Studio do it's thing via Copy Local = true
because Console has a direct dependency that must be solved and Dependency Injection (DI) doesn't even come into the equation. ...那么你应该让 Visual Studio 通过
Copy Local = true
来做这件事,因为 Console 有一个必须解决的直接依赖关系,并且依赖注入(DI)甚至没有进入等式。 If you have a large number of projects, it can be shown to speed builds considerably if the copy happens once at the end but you didn't indicate this is your scenario.如果您有大量项目,如果复制最后发生一次,则可以显示它大大加快了构建速度,但您没有指出这是您的场景。
If however:但是,如果:
...then it's easier to have a Post Build step in one of your projects to copy dependant DLLs once to a single target folder. ...然后在您的项目之一中进行构建后步骤将依赖的 DLL 复制一次到单个目标文件夹会更容易。 This is especially the case when developing plugins/DI for a large solution.
在为大型解决方案开发插件/DI 时尤其如此。
See < project >.参见<项目>。 Properties.Build Events.Post-build event command line
Properties.Build Events.Post-build 事件命令行
It sounds like you are wanting to use DI, but the appearing of Copy Local=true
tells me that your program has a direct relationship to the library anyway.听起来您想使用 DI,但是
Copy Local=true
的出现告诉我您的程序无论如何都与库有直接关系。 What's the point of DI? DI的意义何在? Your's is already strongly-coupled.
你的已经是强耦合了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.