如何将引用的项目导入到 exe 中?

发布于 2024-12-05 21:10:17 字数 142 浏览 0 评论 0 原文

我有一个控制台应用程序,它引用解决方案中的其他项目。当我构建它时,它会在调试中复制这些 dll。我想将它们导入到exe中。如果我将它们添加到资源中然后从那里加载,它们不会更新。我丢失了对引用的 DLL 的更改。有没有办法可以构建它们并将它们导入到每次构建的可执行文件中?

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?

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

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

发布评论

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

评论(3

长亭外,古道边 2024-12-12 21:10:17

您可以使用 ILMerge 将多个程序集合并为一个程序集。

You can use ILMerge to merge several assemblies into one.

零崎曲识 2024-12-12 21:10:17

Jeffrey Richter 有一篇关于这个主题的文章:

http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx< /a>

关键是

对于您添加的每个 DLL 文件,显示其属性并将其构建操作更改为嵌入式资源。

Jeffrey Richter has an article on this very topic:

http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx

The key is

For each DLL file you add, display its properties and change its Build Action to Embedded Resource.

萝莉病 2024-12-12 21:10:17

这是对我有用的解决方案:

http://www.hanselman.com/blog/MishingLanguagesInASingleAssemblyInVisualStudioSeamlessWithILMergeAndMSBuild.aspx

它会在之后合并程序集每个构建都使用 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,您可以单独运行它。

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.

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