C# ILMerge可以';不能运行新的exe

C# ILMerge可以';不能运行新的exe,c#,wpf,ilmerge,C#,Wpf,Ilmerge,更新:解决方案:检查注释中的@Matthew Solution 想要的结果:WPF应用程序exe,可以独立运行,复制到usb并运行,无需安装任何东西 发生了什么:创建了一个新的exe文件,但双击该文件时什么也没有发生 编辑器:Visual Studio 2015 ILMerge:Nuget软件包,2.14.1208 我编辑了*.csproj并添加了构建后操作 <Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Relea

更新:解决方案:检查注释中的@Matthew Solution

想要的结果:WPF应用程序exe,可以独立运行,复制到usb并运行,无需安装任何东西

发生了什么:创建了一个新的exe文件,但双击该文件时什么也没有发生

编辑器:Visual Studio 2015

ILMerge:Nuget软件包,2.14.1208

我编辑了*.csproj并添加了构建后操作

<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release' ">
    <CreateItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)'=='.dll'">
        <Output ItemName="AssembliesToMerge" TaskParameter="Include" />
    </CreateItem>
    <PropertyGroup>
        <ReferenceAssemblies>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1</ReferenceAssemblies>
        <MergedAssembly>$(ProjectDir)publish\MERGED_ASSEMBLY_NAME.exe</MergedAssembly>
        <ExecString>&quot;$(SolutionDir)\packages\ILMerge.2.14.1208\tools\ILMerge.exe&quot; /out:&quot;$(MergedAssembly)&quot; /internalize /allowDup /targetplatform:v4,&quot;$(ReferenceAssemblies)&quot; &quot;@(IntermediateAssembly)&quot; @(AssembliesToMerge->'&quot;%(FullPath)&quot;', ' ')</ExecString>
    </PropertyGroup>
    <Message Importance="high" Text="Executing ILMerge...with target platform from $(ReferenceAssemblies)" />
    <Message Importance="high" Text="$(ExecString)" />
    <Exec Command="$(ExecString)" />
</Target>
现在,在publish文件夹中创建了文件MERGED_ASSEMBLY_NAME.exeMERGED_ASSEMBLY_NAME.pdb。但当我试着运行它时,什么都没发生

在事件查看器中查找并发现这些错误,我认为这些错误是在尝试启动新的exe文件时出现的

Application: MERGED_ASSEMBLY_NAME.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
   at System.Reflection.RuntimeAssembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.RuntimeAssembly.nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.Assembly.Load(System.Reflection.AssemblyName)
   at System.Windows.Navigation.BaseUriHelper.GetLoadedAssembly(System.String, System.String, System.String)
   at MS.Internal.AppModel.ResourceContainer.GetResourceManagerWrapper(System.Uri, System.String ByRef, Boolean ByRef)
   at MS.Internal.AppModel.ResourceContainer.GetPartCore(System.Uri)
   at System.IO.Packaging.Package.GetPartHelper(System.Uri)
   at System.IO.Packaging.Package.GetPart(System.Uri)
   at System.Windows.Application.GetResourceOrContentPart(System.Uri)
   at System.Windows.Application.LoadComponent(System.Object, System.Uri)
   at DrawTools.App.InitializeComponent()
   at DrawTools.App.Main()



Faulting application name: MERGED_ASSEMBLY_NAME.exe, version: 1.0.0.0, time stamp: 0x56f2a475
Faulting module name: KERNELBASE.dll, version: 10.0.10240.16683, time stamp: 0x56ad9410
Exception code: 0xe0434352
Fault offset: 0x000b3fc8
Faulting process id: 0x2e60
Faulting application start time: 0x01d1850e83b32550
Faulting application path: D:\Visual Studio\SortDrawTool\MyDrawTools\publish\MERGED_ASSEMBLY_NAME.exe
Faulting module path: C:\Windows\SYSTEM32\KERNELBASE.dll
Report Id: 29963024-3600-4dd4-8700-33b9f6d9fb37
Faulting package full name: 
Faulting package-relative application ID: 


Fault bucket 129052204427, type 5
Event Name: CLR20r3
Response: Not available
Cab Id: 0

Problem signature:
P1: MERGED_ASSEMBLY_NAME.exe
P2: 1.0.0.0
P3: 56f2a475
P4: mscorlib
P5: 4.6.1055.0
P6: 563c0eac
P7: 40fd
P8: 0
P9: System.IO.FileNotFoundException
P10: 

Attached files:
C:\Users\frbafs01\AppData\Local\Temp\WER6D6E.tmp.WERInternalMetadata.xml
C:\Users\frbafs01\AppData\Local\Temp\WER7697.tmp.appcompat.txt
C:\ProgramData\Microsoft\Windows\WER\Temp\WER76D6.tmp.dmp
C:\Users\frbafs01\AppData\Local\Temp\WER7948.tmp.WERDataCollectionFailure.txt
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_MERGED_ASSEMBLY__46cc5e5a6a376272b10de20c482b0dc4fa7ffcf_ee2c95da_cab_3fc07964\memory.hdmp
WERGenerationLog.txt

These files may be available here:
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_MERGED_ASSEMBLY__46cc5e5a6a376272b10de20c482b0dc4fa7ffcf_ee2c95da_cab_3fc07964

Analysis symbol: 
Rechecking for solution: 0
Report Id: 29963024-3600-4dd4-8700-33b9f6d9fb37
Report Status: 16396
Hashed bucket: 6c9b4e91e20e53298c770adb3262c861
注意:如果我删除/allowDup,则会出现此错误

An exception occurred during merging:
ILMerge.Merge: ERROR!!: Duplicate type 'XamlGeneratedNamespace.GeneratedInternalTypeHelper' found in assembly 'Xceed.Wpf.DataGrid'. Do you want to use the /allowDup option?
   at ILMerging.ILMerge.MergeInAssembly(AssemblyNode a, Boolean makeNonPublic, Boolean targetAssemblyIsComVisible)
   at ILMerging.ILMerge.Merge()
   at ILMerging.ILMerge.Main(String[] args)

你可能应该尝试使用IL重新打包。尝试过重新打包但没有运气。然而@Matthew link工作得很好。你可能应该尝试使用IL-Repack。尝试了Repack,但没有运气。然而@Matthew link工作得非常好。
An exception occurred during merging:
ILMerge.Merge: ERROR!!: Duplicate type 'XamlGeneratedNamespace.GeneratedInternalTypeHelper' found in assembly 'Xceed.Wpf.DataGrid'. Do you want to use the /allowDup option?
   at ILMerging.ILMerge.MergeInAssembly(AssemblyNode a, Boolean makeNonPublic, Boolean targetAssemblyIsComVisible)
   at ILMerging.ILMerge.Merge()
   at ILMerging.ILMerge.Main(String[] args)