C# ILMerge 和 Web 资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ILMerge and Web Resources
提问by John Hoven
We're attemtping to merge our DLL's into one for deployment, thus ILMerge. Almost everything seems to work great. We have a couple web controls that use ClientScript.RegisterClientScriptResource
and these are 404-ing after the merge (These worked before the merge).
我们正在尝试将我们的 DLL 合并为一个以进行部署,即 ILMerge。几乎一切似乎都很好。我们有几个 Web 控件可以使用ClientScript.RegisterClientScriptResource
,它们在合并后是 404-ing(这些在合并之前工作)。
For example one of our controls would look like
例如,我们的控件之一看起来像
namespace Company.WebControls
{
public class ControlA: CompositeControl, INamingContainer
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
this.Page.ClientScript.RegisterClientScriptResource(typeof(ControlA), "Company.WebControls.ControlA.js");
}
}
}
It would be located in Project WebControls, assembly Company.WebControls. Underneath would be ControlA.cs and ControlA.js. ControlA.js is marked as an embedded resource. In the AssemblyInfo.cs I include the following:
它将位于 Project WebControls 程序集 Company.WebControls 中。下面是 ControlA.cs 和 ControlA.js。ControlA.js 被标记为嵌入式资源。在 AssemblyInfo.cs 中,我包含以下内容:
[assembly: System.Web.UI.WebResource("Company.WebControls.ControlA.js", "application/x-javascript")]
After this is merged into CompanyA.dll, what is the proper way to reference this web resource? The ILMerge command line is as follows (from the bin directory after the build): "C:\Program Files\Microsoft\ILMerge\ILMerge.exe" /keyfile:../../CompanySK.snk /wildcards:True /copyattrs:True /out:Company.dll Company.*.dll
将其合并到 CompanyA.dll 后,引用此 Web 资源的正确方法是什么?ILMerge命令行如下(来自构建后的bin目录):"C:\Program Files\Microsoft\ILMerge\ILMerge.exe" /keyfile:../../CompanySK.snk /wildcards:True /copyattrs:True /out:Company.dll Company.*.dll
采纳答案by John Hoven
OK - I got this working. It looks like the primary assembly was the only one whose assembly attributes were being copied. With copyattrs set, the last one in would win, not a merge (as far as I can tell). I created a dummy project to reference the other DLL's and included all the web resources from those projects in the dummy assembly info - now multiple resources from multiple projects are all loading correctly.
好的 - 我得到了这个工作。看起来主程序集是唯一一个其程序集属性被复制的程序集。设置 copyattrs 后,最后一个将获胜,而不是合并(据我所知)。我创建了一个虚拟项目来引用其他 DLL,并将这些项目中的所有 Web 资源包含在虚拟程序集信息中 - 现在来自多个项目的多个资源都正确加载。
Final post-build command line for dummy project: "C:\Program Files\Microsoft\ILMerge\ILMerge.exe" /keyfile:../../Company.snk /wildcards:True /out:Company.dll Company.Merge.dll Company.*.dll
虚拟项目的最终构建后命令行:“C:\Program Files\Microsoft\ILMerge\ILMerge.exe”/keyfile:../../Company.snk /wildcards:True /out:Company.dll Company.Merge .dll 公司.*.dll
回答by Genady Sergeev
You need to set /allowMultiple along with /copyattrs. It is only then that ILMerge will merge the embedded resources from all assemblies.
您需要设置 /allowMultiple 和 /copyattrs。只有这样,ILMerge 才会合并来自所有程序集的嵌入资源。