2016-10-29 3 views
1

ILMerge, .NET 4, NuGet: Нерешенная ссылка сборки не допускаются: CommandLineILMerge, .NET 4, NuGet: Нерешенная ссылка сборки не допускается: CommandLine

Я пытаюсь упаковать мой проект в одной DLL.
Я использую:
- Visual Studio 2015
- NuGet
- ILMerge

Для достижения своей цели, я бы взял ILMerge batch file
Добавлен событие после сборки:

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

Затем слегка измененный пакетный файл, чтобы избавиться от повторяющихся ошибок и добавить некоторые крючки, чтобы попытаться устранить ошибку «Неразрешенная ссылка на сборку».

К сожалению, ни один из Google Suggestions
Принесли рельеф.

Итак, я еще получил ошибку:

Unresolved assembly reference not allowed: 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) 

Извините за длинный пост, но у меня недостаточно маны, чтобы вставить более двух ссылок, поэтому пришлось вставлять журнал прямо в поток, а поддержка Markdown здесь действительно отстой.

+0

Я на самом деле не настаиваю на решении моей проблемы сразу. Может быть, кто-то хотя бы знает, как отладить его, чтобы выяснить причину проблемы? – registered

ответ

0

AssemblyResolver: Assembly 'YouTrackSharp' is referencing assembly 'CommandLine'.

Похоже, некоторые комплектующие имеет ссылку на CommandLine компонента, в то время как строка параметра ILMerge не содержит эту ссылку (как я могу видеть из журнала).

В попытке решить эту проблему попробуйте указать параметр /useFullPublicKeyForReferences для вызова ILMerge. Если это не помогает, попробуйте указать Местоположение библиотеки CommandLine.

Смежные вопросы