简体   繁体   English

我该如何暂时停用MSBuild.ILMerge.Task?

[英]How can I temporarily inactivate MSBuild.ILMerge.Task?

I am using the NuGet package MSBuild.ILMerge.Task in order to combine .NET external dlls to a single executable file. 我正在使用NuGet包MSBuild.ILMerge.Task将.NET外部dll组合到一个可执行文件中。 It works like a charm. 它就像一个魅力。

Now, when I try to edit while Debugging, Visual Studio says: 现在,当我尝试在调试时进行编辑时,Visual Studio说:

Changes are not allowed if the assembly has not been loaded 如果尚未加载程序集,则不允许进行更改

I guess it's the downside of having all the dependencies into a single .exe (I don't know about that, it's just a guess). 我想这是将所有依赖项都放入单个.exe中的缺点(我不知道,这只是猜测)。

But anyway, it would make sense to have MSBuild.ILMerge.Task on Build, but inactive on Debug. 但无论如何,在Build上使用MSBuild.ILMerge.Task是有意义的,但在Debug上是不活动的。 Does anybody know how to achieve this? 有谁知道如何实现这一目标?

Notice that when MSBuild.ILMerge.Task is installed through NuGet, when you hit "rebuild" it automatically creates the single .exe (letting the .config file outside, of course, plus a .pdb). 请注意,当通过NuGet安装MSBuild.ILMerge.Task时,当您点击“rebuild”时,它会自动创建单个.exe(当然,将.config文件放在外面,加上.pdb)。 You don't need to configure anything, and this why I am not able to guess the inner workings of the process and how to inactivate it. 您不需要配置任何东西,这就是为什么我无法猜测流程的内部工作原理以及如何将其取消激活。


For more information, I am writing a blog post about ILMerge. 有关更多信息,我正在写一篇关于ILMerge的博客文章。 I am trying to document all how-to's, problems and caveats: 我想记录所有的方法,问题和警告:

http://localcode.wikidot.com/merge-all-binary-files-dll-s-etc-into-a-single-exe http://localcode.wikidot.com/merge-all-binary-files-dll-s-etc-into-a-single-exe


Edit1: I've noticed that the NuGet package automatically sets a .props file with the following info: Edit1:我注意到NuGet包自动设置一个.props文件,其中包含以下信息:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

I've started looking for DefaultTargets="Build" and a way to disable on debug, and I've found this post that seems to explain how. 我已经开始寻找DefaultTargets="Build"以及一种在调试时禁用的方法,我发现这篇文章似乎解释了如何。


Edit2: EDIT2:

If remove this lines from my .csproj, then it skips the ILMerge compilation correctly: 如果从我的.csproj中删除这一行,那么它会正确跳过ILMerge编译:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
  <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.props'))" />
<Error Condition="!Exists('..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets'))" />
</Target>
<Import Project="..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets" Condition="Exists('..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets')" />  

It's something, but it looks a bit handcrafted and impractical for the moment... 这是什么,但它看起来有点手工制作,目前还不切实际......

You can choose to run ILMerge only for "Release" builds, and leave it out of "Debug" builds, in which case you can use the debugger as you normally would in Debug builds, but change to Release only when you're ready to merge your assemblies into a single executable. 您可以选择仅针对“Release”构建运行ILMerge,并将其从“Debug”构建中删除,在这种情况下,您可以像在Debug构建中一样使用调试器,但只有在准备好时才更改为Release将程序集合并为单个可执行文件。

You can do this by editing your .csproj file and changing this line: 您可以通过编辑.csproj文件并更改此行来执行此操作:

<Import
  Project="..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets"
  Condition="Exists('..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets')" />

to: 至:

<Import
  Project="..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets" 
  Condition="'$(Configuration)'=='Release' AND Exists('..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets')" />

the difference being inserting the '$(Configuration)'=='Release' AND to the Condition attribute. 不同之处在于将'$(Configuration)'=='Release' AND插入到Condition属性中。

Use the Debug / Release dropdown menu in your Visual Studio toolbar to toggle between build configurations. 使用Visual Studio工具栏中的“调试/发布”下拉菜单在构建配置之间切换。 Or, alternatively, open Build > Configuration Manager and change the "Active solution configuration". 或者,打开Build> Configuration Manager并更改“Active solution configuration”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 指定要与MSBuild.ILMerge.Task合并的文件 - Specify files to merge with MSBuild.ILMerge.Task 未解析的程序集引用不允许 Newtonsoft.Json 和 MSBuild.ILMerge.Task - Unresolved Assembly reference not allowed Newtonsoft.Json with MSBuild.ILMerge.Task 从DevOps Nuget Artifact软件包中删除MSBuild.ILMerge.Task依赖项 - Remove MSBuild.ILMerge.Task Dependency from DevOps Nuget Artifact Package Visual Studio C# MSBuild.ILMerge.Task 问题 程序集未标记为仅包含托管代码 - Visual Studio C# MSBuild.ILMerge.Task problem with The assembly is not marked as containing only managed code 如何在MSBuild任务中获取当前的CodeDomProvider - How can I get the current CodeDomProvider in an MSBuild Task 如何在没有ILMerge的情况下将程序集嵌入到控制台应用程序中? - how can I embed an assembly into a console application without ILMerge? 为什么我不能ILMerge Zxing? - Why I can't ILMerge Zxing? 当我的项目使用Csc任务时,如何强制MSBuild尊重解决方案中的项目依赖关系? - How can I force MSBuild to respect project dependencies in my solution when my project uses a Csc task? MSBuild,我可以使用 UsingTask output 并在复制任务中使用它吗? - MSBuild, Can I take UsingTask output and use it in a Copy task? 通过ILMerge将DLL嵌入到exe中,我无法访问dll - Embedded a DLL into the exe through ILMerge, I can't access the dll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM