ILMerge,.NET 4,NuGet:不允许未解析的程序集引用:CommandLine

时间:2016-10-29 13:40:37

标签: .net-4.0 ilmerge

ILMerge,.NET 4,NuGet:不允许未解析的程序集引用:CommandLine

我正在尝试将我的项目打包成单个dll 我正在使用:
- Visual Studio 2015
- NuGet
- ILMerge

为了实现我的目标,我接受了ILMerge batch file 添加了一个构建后事件:

"d:\#programming\#visual_studio\merge_all.bat" "$(TargetPath)" $(ConfigurationName)  

然后稍微修改批处理文件以消除重复错误并添加一些钩子以尝试消除“未解决的程序集引用”错误。

不幸的是,Google Suggestions没有 带来任何宽慰。

所以,我仍然有一个错误:

  

不允许使用未解析的程序集引用:CommandLine。

这是我的ILMerge批处理文件:

@ECHO OFF

rem # usage 
rem # "path\to\merge_all.bat" "$(TargetPath)" $(ConfigurationName)
rem # "d:\#programming\#visual_studio\merge_all.bat" "$(TargetPath)" $(ConfigurationName)

rem #    set .NET version and output folder name
set net_version=v4

set net_path="C:\Windows\Microsoft.NET\Framework\v4.0.30319"
set net_path_v1="%ProgramFiles%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client"
set net_path_v2="%ProgramFiles%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"
set net_path_v3="%ProgramFiles%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6"

set target_platform=%net_version%,%net_path_v3%
set lib_path="%ProgramFiles%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"

set output=merged

set ILMerge=%ProgramFiles%\Microsoft\ILMerge\ILMerge.exe

rem # parsing arguments
set target_path=%1
set target_file=%~nx1
set target_dir=%~dp1
set ConfigurationName=%2

rem #    set output path and result file path
set outdir=%target_dir%%output%
set result=%outdir%\%target_file%
set log_file="%outdir%\merge.log"

set primary_assembly=%target_path%

rem # a little looping voodoo from microsoft to get rid of "duplicate" error
setlocal EnableDelayedExpansion
set "other_assemblies="

for %%f in (%target_dir%*.dll) do (

    if NOT %%~nxf==%target_file% (
        set "other_assemblies=!other_assemblies! %target_dir%%%~nxf"
    )
)
setlocal DisableDelayedExpansion

rem #    print info
@echo     Start %ConfigurationName% Merging %target_file%. 
@echo Target: %target_path%
@echo target_dir: %target_dir%
@echo Config: %ConfigurationName% 
@echo Log: %log_file%
@echo primary assembly: %primary_assembly%
@echo other assemblies: %other_assemblies%

rem #    recreate outdir
IF EXIST "%outdir%" rmdir /S /Q "%outdir%"
md "%outdir%"

set options= /wildcards /targetplatform:%target_platform% /log:%log_file% /out:"%result%" %primary_assembly% %other_assemblies%

rem #    run merge cmd
@echo Merging: '"%ILMerge%" %options%'
"%ILMerge%" %options%

rem #    if succeded
IF %ErrorLevel% EQU 0 (

    rem #    clear real output folder and put there result assembly
    IF %ConfigurationName%==Release (

        del  %target_dir%*.*
        del  %target_dir%*.dll
        del  %target_dir%*.pdb
        del  %target_dir%*.xml
        del  %target_dir%*.*

        copy %result% %target_dir%
        rmdir /S /Q %outdir%
        set result=%target_path% 
        @echo Result: %target_file% "->  %target_path%"
    ) ELSE (
       @echo Result: %target_file% "->  %result%" )

   set status=succeded
   set errlvl=0    
) ELSE (
    set status=failed 
    set errlvl=1
    )

@echo Merge %status%
exit %errlvl% 

以下是构建过程的输出:

1>------ Rebuild All started: Project: YouTrackSharpApiWrapper, Configuration: Debug Any CPU ------
1>D:\#programming\#visual_studio\YouTrackSharpApiWrapper\ApiWrapper.cs(59,21,59,22): warning CS0168: The variable 'e' is declared but never used
1>  YouTrackSharpApiWrapper -> D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharpApiWrapper.dll
1>      Start Debug Merging YouTrackSharpApiWrapper.dll. 
1>  Target: "D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharpApiWrapper.dll"
1>  target_dir: D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\
1>  Config: Debug 
1>  Log: "D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\merged\merge.log"
1>  primary assembly: "D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharpApiWrapper.dll"
1>  other assemblies:  D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\EasyHttp.dll D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\JsonFx.dll D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharp.dll
1>  Merging: '"C:\Program Files (x86)\Microsoft\ILMerge\ILMerge.exe"  /wildcards /targetplatform:v4,"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6" /log:"D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\merged\merge.log" /out:"D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\merged\YouTrackSharpApiWrapper.dll" "D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharpApiWrapper.dll"  D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\EasyHttp.dll D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\JsonFx.dll D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharp.dll'
1>  Merge failed 
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(4714,5): error MSB3073: The command ""d:\#programming\#visual_studio\merge_all.bat" "D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharpApiWrapper.dll" Debug" exited with code 1.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

这是ILMerge的日志:

ILMerge version 2.12.803.0
Copyright (C) Microsoft Corporation 2004-2006. All rights reserved.
ILMerge /wildcards /targetplatform:v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6 /log:D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\merged\merge.log /out:D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\merged\YouTrackSharpApiWrapper.dll D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharpApiWrapper.dll D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\EasyHttp.dll D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\JsonFx.dll D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharp.dll 
Set platform to 'v4', using directory 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6' for mscorlib.dll
Running on Microsoft (R) .NET Framework v2.0.50727
mscorlib.dll version = 2.0.0.0
The list of input assemblies is:
    D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharpApiWrapper.dll
    D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\EasyHttp.dll
    D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\JsonFx.dll
    D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharp.dll
The number of files matching the pattern D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharpApiWrapper.dll is 1.
D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharpApiWrapper.dll
Trying to read assembly from the file 'D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharpApiWrapper.dll'.
    Successfully read in assembly.
    There were no errors reported in YouTrackSharpApiWrapper's metadata.
The number of files matching the pattern D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\EasyHttp.dll is 1.
D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\EasyHttp.dll
Trying to read assembly from the file 'D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\EasyHttp.dll'.
    Successfully read in assembly.
    There were no errors reported in EasyHttp's metadata.
The number of files matching the pattern D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\JsonFx.dll is 1.
D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\JsonFx.dll
Trying to read assembly from the file 'D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\JsonFx.dll'.
Can not find PDB file. Debug info will not be available for assembly 'D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\JsonFx.dll'.
    Successfully read in assembly.
    There were no errors reported in JsonFx's metadata.
The number of files matching the pattern D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharp.dll is 1.
D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharp.dll
Trying to read assembly from the file 'D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\YouTrackSharp.dll'.
    Successfully read in assembly.
    There were no errors reported in YouTrackSharp's metadata.
Checking to see that all of the input assemblies have a compatible PeKind.
    YouTrackSharpApiWrapper.PeKind = ILonly
    EasyHttp.PeKind = ILonly
    JsonFx.PeKind = ILonly
    YouTrackSharp.PeKind = ILonly
All input assemblies have a compatible PeKind value.
AssemblyResolver: Assembly 'EasyHttp' is referencing assembly 'System.Core'.
    AssemblyResolver: Attempting referencing assembly's directory.
    AssemblyResolver: Did not find assembly in referencing assembly's directory.
    AssemblyResolver: Attempting input directory.
    AssemblyResolver: Did not find assembly in input directory.
    AssemblyResolver: Attempting user-supplied directories.
    AssemblyResolver: No user-supplied directories.
    AssemblyResolver: Attempting framework directory.
Can not find PDB file. Debug info will not be available for assembly 'System.Core'.
Resolved assembly reference 'System.Core' to 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Core.dll'. (Used framework directory.)
AssemblyResolver: Assembly 'YouTrackSharp' is referencing assembly 'System.Management.Automation'.
    AssemblyResolver: Attempting referencing assembly's directory.
    AssemblyResolver: Did not find assembly in referencing assembly's directory.
    AssemblyResolver: Attempting input directory.
    AssemblyResolver: Did not find assembly in input directory.
    AssemblyResolver: Attempting user-supplied directories.
    AssemblyResolver: No user-supplied directories.
    AssemblyResolver: Attempting framework directory.
    AssemblyResolver: Did not find assembly in framework directory.
AssemblyResolver: Unable to resolve reference. (It still might be found, e.g., in the GAC.)
AssemblyResolver: Assembly 'YouTrackSharp' is referencing assembly 'CommandLine'.
    AssemblyResolver: Attempting referencing assembly's directory.
    AssemblyResolver: Did not find assembly in referencing assembly's directory.
    AssemblyResolver: Attempting input directory.
    AssemblyResolver: Did not find assembly in input directory.
    AssemblyResolver: Attempting user-supplied directories.
    AssemblyResolver: No user-supplied directories.
    AssemblyResolver: Attempting framework directory.
    AssemblyResolver: Did not find assembly in framework directory.
AssemblyResolver: Unable to resolve reference. (It still might be found, e.g., in the GAC.)
Using assembly 'YouTrackSharpApiWrapper' for assembly-level attributes for the target assembly.
Merging assembly 'YouTrackSharpApiWrapper' into target assembly.
Merging assembly 'EasyHttp' into target assembly.
Merging assembly 'JsonFx' into target assembly.
Assembly level attribute 'System.Security.AllowPartiallyTrustedCallersAttribute' from assembly 'JsonFx' being deleted from target assembly
Merging assembly 'YouTrackSharp' into target assembly.
Copying 1 Win32 Resources from assembly 'YouTrackSharpApiWrapper' into target assembly.
    There were no errors reported in the target assembly's metadata.
ILMerge: Writing target assembly 'D:\#programming\#visual_studio\YouTrackSharpApiWrapper\bin\Debug\merged\YouTrackSharpApiWrapper.dll'.
AssemblyResolver: Assembly 'YouTrackSharp' is referencing assembly 'Microsoft.CSharp'.
    AssemblyResolver: Attempting referencing assembly's directory.
    AssemblyResolver: Did not find assembly in referencing assembly's directory.
    AssemblyResolver: Attempting input directory.
    AssemblyResolver: Did not find assembly in input directory.
    AssemblyResolver: Attempting user-supplied directories.
    AssemblyResolver: No user-supplied directories.
    AssemblyResolver: Attempting framework directory.
Can not find PDB file. Debug info will not be available for assembly 'Microsoft.CSharp'.
Resolved assembly reference 'Microsoft.CSharp' to 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\Microsoft.CSharp.dll'. (Used framework directory.)
An exception occurred during merging:
Unresolved assembly reference not allowed: CommandLine.
   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.GetMemberRefIndex(Member m)
   at System.Compiler.Ir2md.GetMethodToken(Method m)
   at System.Compiler.Ir2md.VisitConstruct(Construct cons)
   at System.Compiler.Ir2md.VisitExpressionList(ExpressionList expressions)
   at System.Compiler.Ir2md.VisitConstruct(Construct cons)
   at System.Compiler.Ir2md.VisitAssignmentStatement(AssignmentStatement assignment)
   at System.Compiler.Ir2md.VisitBlock(Block block)
   at System.Compiler.Ir2md.VisitBlock(Block block)
   at System.Compiler.Ir2md.VisitMethodBody(Method method)
   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)

很抱歉很长的帖子,但是我没有足够的法术力来插入超过2个链接,所以不得不在日志中粘贴日志,而Markdown支持在这里真的很糟糕。

1 个答案:

答案 0 :(得分:1)

  

AssemblyResolver:Assembly' YouTrackSharp'正在引用程序集' CommandLine'。

似乎有些组件引用了 CommandLine 组件,而ILMerge参数字符串并不包含该引用(正如我从日志中看到的那样)。

尝试解决此问题时,请尝试为ILMerge调用指定 / useFullPublicKeyForReferences 参数。如果它没有帮助,请尝试在最后指定 CommandLine 库位置。