在 Visual Studio 项目中引用使用 ILMerge 创建的程序集
我在 Visual Studio 中有一个包含 5 个项目的解决方案。它们是:
Foo.Core
:核心功能Foo.Api
:在核心之上构建的生成代码Foo.Api
: >Foo.Web
:特定于 Web 的扩展Foo.Web.Mvc
:特定于 MVC 的扩展Newtonsoft.Json
:第 3 方库
我想使用 ILMerge 合并 Foo.Core
、Foo.Api
和 Newtonsoft.Json
到一个名为 Foo
的程序集中。这是最简单的部分。
我遇到的问题是 Foo.Web 和 Foo.Web.Mvc 都需要引用所有三个合并的程序集。
如果我引用原始程序集,则在执行 ILMerge 后它们将具有无效引用。
如果我引用 ILMerged 程序集,我必须引用调试程序集,然后在打包所有内容之前更改它,这似乎并不理想。
我尝试创建一个名为 Foo 的项目,它引用 3 个合并的程序集并用 ILmerged 程序集替换其自己的输出,但这似乎根本不起作用。
有可靠的方法来做到这一点吗?
I have a solution in Visual Studio with 5 projects. They are:
Foo.Core
: Core functionalityFoo.Api
: Generated code built on top of coreFoo.Web
: Web-specific extensionsFoo.Web.Mvc
: MVC-specific extensionsNewtonsoft.Json
: 3rd party library
I want to use ILMerge to merge Foo.Core
, Foo.Api
and Newtonsoft.Json
into a single assembly, called Foo
. That's the easy part.
The problem I'm running into is that Foo.Web
and Foo.Web.Mvc
both need to reference all three of the merged assemblies.
If I reference the original assemblies, they will have invalid references after I do the ILMerge.
If I reference the ILMerged assembly, I have to reference a debug assembly and then change it before I package everything up, which doesn't seem ideal.
I've tried creating a project called Foo
, which references the 3 merged assemblies and replaces its own output with the ILmerged assembly, but that doesn't seem to work at all.
Is there a reliable way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道我来得太晚了,但我们一直在努力解决这个完全相同的问题,这就是我们解决它的方法。
首先,我们编辑了所有非合并或附属项目的 csproj 文件,以使用 条件根据文件的存在来引用外部程序集。在本例中,我们将测试合并程序集是否存在。然后我们运行一个构建脚本,该脚本执行以下操作:
I know I'm coming really late to the game, but we were struggling with this exact same problem and here is how we solved it.
First, we edited the csproj files of all non-merged or satellite projects to use a conditional reference to an external assembly based upon existence of a file. In this case, we're going to test for the existence of the merged assembly. Then we ran a build script which does the following:
ILMerge 旨在创建一个新的包/组件作为盒装“产品”(API、程序...),以简化程序集管理,例如部署、gac 引用、程序集可见性等,以供一体式使用或外部使用,不混合。
我的猜测是,如果您有一个或一个
PreBuildEvent
,您必须在主程序集/项目(Foo.Api
?)上设置一个PostBuildEvent
您的Foo.Web
和Foo.Web.Mvc
项目来生成合并的Foo
,它将在您的Foo.Web< 中引用/code> 和 Foo.Web.Mvc
项目作为外部程序集。您可以通过设置 MsBuild 任务使其在 Visual Studio 中更加集成。 示例(来自
Stackoverflow)。
ILMerge is designed to create a new package/component as a boxed 'product' (API,Program...) to simplify assembly management like deployment, gac referencement, assembly visibility and more either for all-in-one use or external use, not mixed.
My guess is you have to setup a
PostBuildEvent
on your main assembly/project (Foo.Api
?) if you have one or aPreBuildEvent
in yourFoo.Web
andFoo.Web.Mvc
projects to generate your mergedFoo
which will be referenced in yourFoo.Web
andFoo.Web.Mvc
projects as an external assembly.You can make this more integrated in Visual Studio by setting up a MsBuild task. A sample (from
Stackoverflow).