./p>
它会在每次构建后使用ILMerge合并程序集(如注释中所建议).我需要为.NET Framework 4更新.targets文件.以防万一有人需要它:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
<CreateItem Include="@(ReferencePath)" Condition="'%(CopyLocal)'=='true' and '%(ReferencePath.IlMerge)'=='true'">
<Output TaskParameter="Include" ItemName="IlmergeAssemblies"/>
</CreateItem>
<Message Text="MERGING: @(IlmergeAssemblies->'%(Filename)')" Importance="High" />
<Exec Command=""$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe" /out:@(MainAssembly) "@(IntermediateAssembly)" @(IlmergeAssemblies->'"%(FullPath)"', ' ') /target:exe /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /wildcards" />
</Target>
<Target Name="_CopyFilesMarkedCopyLocal"/>
</Project>
更新
尽管上述解决方案有效,但您可以使其更简单,并且不需要目标文件.您可以将ILMerge放在解决方案中的某个位置.然后在构建后从那里调用它.您只需ILMerge.exe,将其复制到/solutionDirectory/Tools
这样的位置.在构建后事件命令行中编写命令.
$(SolutionDir)Tools\ILMerge.exe /out:"$(ProjectDir)bin\Debug\WindowsGUI.exe" "$(ProjectDir)obj\x86\Debug\WindowsGUI.exe" "$(SolutionDir)BusinessLayer\bin\Debug\BusinessLayer.dll" /target:exe /targetplatform:v4,"$(MSBuildBinPath)" /wildcards
构建后,您将获得带有嵌入式DLL的.exe,并且可以单独运行它.
I have a console application which is referencing other projects in solution. When I build it, it will copy those dlls in Debug. I want to import them in the exe. If I add them to resources then load from there, they are not updated. I lose the changes on referenced DLLs. Is there a way that I can build them and import them in the executable file on each build?
解决方案
Here's the solution that worked for me:
http://www.hanselman.com/blog/MixingLanguagesInASingleAssemblyInVisualStudioSeamlesslyWithILMergeAndMSBuild.aspx
It merges assemblies after each build with ILMerge (like suggested in comments). I needed to update .targets file for .NET Framework 4. In case anyone needs it:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
<CreateItem Include="@(ReferencePath)" Condition="'%(CopyLocal)'=='true' and '%(ReferencePath.IlMerge)'=='true'">
<Output TaskParameter="Include" ItemName="IlmergeAssemblies"/>
</CreateItem>
<Message Text="MERGING: @(IlmergeAssemblies->'%(Filename)')" Importance="High" />
<Exec Command=""$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe" /out:@(MainAssembly) "@(IntermediateAssembly)" @(IlmergeAssemblies->'"%(FullPath)"', ' ') /target:exe /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /wildcards" />
</Target>
<Target Name="_CopyFilesMarkedCopyLocal"/>
</Project>
Update
While the solution above works, you can make it simpler and you wouldn't need the targets files. You can put ILMerge somewhere in solution. Then call it from there after build. ILMerge.exe is all you need, copy it in somewhere like /solutionDirectory/Tools
. Write a command in your post-build event command line.
$(SolutionDir)Tools\ILMerge.exe /out:"$(ProjectDir)bin\Debug\WindowsGUI.exe" "$(ProjectDir)obj\x86\Debug\WindowsGUI.exe" "$(SolutionDir)BusinessLayer\bin\Debug\BusinessLayer.dll" /target:exe /targetplatform:v4,"$(MSBuildBinPath)" /wildcards
After the build, you get the .exe with embedded DLLs and you can run it alone.
这篇关于如何将引用的项目导入exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!