在msbuild中获取已解析的引用路径列表

发布于 2024-12-19 08:04:43 字数 1930 浏览 2 评论 0原文

我正在尝试使用 ILMerge 将多个程序集合并到一个插件程序集中,该插件程序将由另一个应用程序动态加载。

使用社区任务,到目前为止,我已经得到:

<Target Name="CombineAssemblies" AfterTargets="MvcBuildViews">
    <ItemGroup>
        <MergePaths Include="@(_ResolvedProjectReferencePaths)" />
        <!--<MergePaths Include="%(Reference.ResolvedPath)" /> This doesn't work! -->
    </ItemGroup>

    <ILMerge
        DebugInfo="true"
        LogFile="log.txt"
        InputAssemblies="@(MergePaths)"
        OutputFile="&quot;$(TargetPath)&quot;"
        CopyAttributes="true"
        TargetPlatformVersion="v4"/>
</Target>

使用 @(_ResolvedProjectReferencePaths) 对于项目引用效果很好,并且它们的路径正确传递到 ILMerge 任务。

通过 MSBuild 运行此程序时,ILMerge.exe 会出错。查看日志文件,我得到:

Unresolved assembly reference not allowed: System.Web.Mvc.
   at System.Compiler.Ir2md.GetAssemblyRefIndex(AssemblyNode assembly)
   at System.Compiler.Ir2md.GetTypeRefIndex(TypeNode type)
   at System.Compiler.Ir2md.VisitReferencedType(TypeNode type)
   at System.Compiler.Ir2md.VisitMethod(Method method)
   at System.Compiler.Ir2md.VisitClass(Class Class)
   at System.Compiler.Ir2md.VisitModule(Module module)
   at System.Compiler.Ir2md.SetupMetadataWriter(String debugSymbolsLocation)
   at System.Compiler.Ir2md.WritePE(Module module, String debugSymbolsLocation, BinaryWriter writer)
   at System.Compiler.Writer.WritePE(String location, Boolean writeDebugSymbols, Module module, Boolean delaySign, String keyFileName, String keyName)
   at System.Compiler.Writer.WritePE(CompilerParameters compilerParameters, Module module)
   at ILMerging.ILMerge.Merge()
   at ILMerging.ILMerge.Main(String[] args)

我正在引用 MVC 库,从日志文件中我认为 ILMerge 无法解析这些库,即使它们在实际编译过程中已正确解析。

因此,我希望将这些库的位置传递给 ILMerge,最好使用引用项,这样我就不必手动添加一堆引用路径,如果我添加或删除引用,这些路径就必须更改。对于普通引用,是否有一些相当于 @(_ResolvedProjectReferencePaths) 的东西?

谢谢!

I'm trying to use ILMerge to merge multiple assemblies into one plugin assembly, which will be dynamically loaded by another application.

Using the community tasks, I've so far got:

<Target Name="CombineAssemblies" AfterTargets="MvcBuildViews">
    <ItemGroup>
        <MergePaths Include="@(_ResolvedProjectReferencePaths)" />
        <!--<MergePaths Include="%(Reference.ResolvedPath)" /> This doesn't work! -->
    </ItemGroup>

    <ILMerge
        DebugInfo="true"
        LogFile="log.txt"
        InputAssemblies="@(MergePaths)"
        OutputFile=""$(TargetPath)""
        CopyAttributes="true"
        TargetPlatformVersion="v4"/>
</Target>

Using @(_ResolvedProjectReferencePaths) works fine for the project references, and their paths are passesd correctly through to the ILMerge task.

When running this through MSBuild, ILMerge.exe errors out. Looking at the log file, I get:

Unresolved assembly reference not allowed: System.Web.Mvc.
   at System.Compiler.Ir2md.GetAssemblyRefIndex(AssemblyNode assembly)
   at System.Compiler.Ir2md.GetTypeRefIndex(TypeNode type)
   at System.Compiler.Ir2md.VisitReferencedType(TypeNode type)
   at System.Compiler.Ir2md.VisitMethod(Method method)
   at System.Compiler.Ir2md.VisitClass(Class Class)
   at System.Compiler.Ir2md.VisitModule(Module module)
   at System.Compiler.Ir2md.SetupMetadataWriter(String debugSymbolsLocation)
   at System.Compiler.Ir2md.WritePE(Module module, String debugSymbolsLocation, BinaryWriter writer)
   at System.Compiler.Writer.WritePE(String location, Boolean writeDebugSymbols, Module module, Boolean delaySign, String keyFileName, String keyName)
   at System.Compiler.Writer.WritePE(CompilerParameters compilerParameters, Module module)
   at ILMerging.ILMerge.Merge()
   at ILMerging.ILMerge.Main(String[] args)

I'm referencing the MVC libraries, which from the log file I assume could not be resolved by ILMerge, even though they are resolved correctly in the actual compilation process.

I therefore want to pass the location of these libraries through to ILMerge, ideally using the References item so I don't have to manually add a bunch of reference paths which would have to change if I added or removed references. Is there some equivalent to @(_ResolvedProjectReferencePaths) for normal references?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

箹锭⒈辈孓 2024-12-26 08:04:43

尝试 @(ReferencePath),它应该在目标 ResolveAssemblyReferences 之后使用。

Try @(ReferencePath), which should be used after target ResolveAssemblyReferences.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文