The "MSBuild.ExtensionPack.Framework.ILMerge" task failed unexpectedly.

Dec 4, 2011 at 4:50 PM

Hello,

I am trying to merge all assemblies in a ASP.NET MVC 3 project and I am using the following:

  <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks" />

  <Target Name="AfterBuild">
    <ItemGroup>
      <Input Include="$(ProjectDir)\Bin\AttributeRouting.dll" />
      <Input Include="$(ProjectDir)\Bin\AjaxMin.dll" />
    </ItemGroup>
    <MSBuild.ExtensionPack.Framework.ILMerge InputAssemblies="@(Input)" TargetPlatformVersion="v4" OutputFile="C:\Users\Miguel\Desktop\Merged.dll" LogFile="C:\Users\Miguel\Desktop\ILMergeLog.log" LogMessages="true" />
  </Target>

I don't get anything in the log but I get the following error on Visual Studio:

Error    1    The "MSBuild.ExtensionPack.Framework.ILMerge" task failed unexpectedly.
System.NullReferenceException: Object reference not set to an instance of an object.
   at MSBuild.ExtensionPack.Framework.ILMerge.GenerateCommandLineCommands() in D:\Projects\MSBuildExtensionPack\Releases\4.0.4.0\Main\Framework\Framework\ILMerge.cs:line 328
   at Microsoft.Build.Utilities.ToolTask.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)

Any idea what is wrong? Is it a problem with my code?

Two site questions:

1 - Instead of enumerating all DLL's can I say to merge all DLL references in this project?

2 - Is it possible to create a T4 template that when I add it to the project the MERGE code lines are added automatically to project file?

Thank You,

Miguel

Coordinator
Dec 5, 2011 at 6:08 PM

Hi Miguel

You need to provide the TargetPlatformDirectory too, e.g.

 

TargetPlatformVersion="v4" TargetPlatformdirectory="c:\Windows\Microsoft.NET\Framework\v4.0.30319"

I'll update the docs to make it more explicit.

 

re 1: Not with current task, but you could write an (inline) task to get the info and then pass it to the ILMerge task,

re 2: Sorry, I've not worked with T4 for many years though if I remember correctly there was little that couldn't be done with it :-)

 

Mike

Dec 5, 2011 at 9:57 PM
Edited Dec 5, 2011 at 10:04 PM

Hello Mike,

I was able to solve it by adding TargetPlatformDirectory. Thank You.

1 - About selecting all DLL's I am not sure what you mean with Inline Task. Could you, please, give me an example?

     What I have been trying is the following:

  <Target Name="AfterBuild">

    <ItemGroup>
      <Input Include="$(ProjectDir)\Bin\*.*" />
    </ItemGroup>

    <MSBuild.ExtensionPack.Framework.ILMerge InputAssemblies="@(Input)" TargetPlatformVersion="v4" TargetPlatformdirectory="c:\Windows\Microsoft.NET\Framework\v4.0.30319" OutputFile="$(OutputPath)\Merged.Site.dll" />
   
  </Target>

     Shouldn't this work?

     After searching it seems this is how it is usually done.

2 - Thanks. I will check it out.

3 - After merging the resulting assembly gets the details (Name, Version, ...) of the first assembly in list.

     Is it possible to do it another way?

4 - Is there an option to in ILMerge task to delete all Merged assemblies after merging.

     I was reading it but couldn't find it. This would be a useful option, for example, when publishing the application to the server.

Thank you,

Miguel

Coordinator
Dec 5, 2011 at 10:14 PM

Great.

1. Looks ok to me. See this MSBuild Inline Tasks to the rescue. Basically if you need to do anything that you dont have a task for you can go the inline route if you are on .net 4.0. You seem to have stuff working now though.

3. You can pass in Version and OutputFile

4. No I dont think so. Feel free to raise an Issue and I'll get it scheduled.

 

Mike

Dec 7, 2011 at 12:44 AM

"1. Looks ok to me. See this MSBuild Inline Tasks to the rescue. Basically if you need to do anything that you dont have a task for you can go the inline route if you are on .net 4.0. You seem to have stuff working now though."

I think you miss understand me. It is not working with:

 <ItemGroup>
   <Input Include="$(ProjectDir)\Bin\*.*" />
 </ItemGroup>

It only works when I enumerate all files. But shouldn't this work?

I don't understand why a Inline Task needs to be used.

4 - I just raised the issue to delete original files.

Thank You,

Miguel

 



Coordinator
Dec 18, 2011 at 10:10 PM

4 - DeleteInputAssemblies now supported - http://msbuildextensionpack.codeplex.com/SourceControl/changeset/changes/72529

Marked as answer by mikeFourie on 5/26/2014 at 10:04 AM
Sep 24, 2012 at 11:18 AM
Edited Sep 24, 2012 at 11:19 AM

You can use the GetFrameworkPath task to get the framework path so that you don't have to hard code it.

<GetFrameworkPath>
	<Output TaskParameter="FrameworkVersion40Path" PropertyName="FrameworkPath" />
</GetFrameworkPath>

<MSBuild.ExtensionPack.Framework.ILMerge InputAssemblies="@(Input)" TargetPlatformVersion="v4" TargetPlatformdirectory="$(FrameworkPath)" />
Marked as answer by mikeFourie on 5/26/2014 at 10:04 AM