Code Monkey home page Code Monkey logo

ilmerge-msbuild-task's Introduction

Configurable ILMerge Task for MSBuild

Adds ILMerge to Visual Studio 2013/2017 or automated builds. This Task is intended to work right out of the box however, it supports a configuration file where you can control every ILMerge property including the list of assemblies to be merged.

Getting Started

Use Nuget to add ILMerge.MSBuild.Task to your Visual Studio project:

Install-Package ILMerge.MSBuild.Task

Build your project. The merged assembly will be stored in an ILMerge folder under your project output. The output directory is configurable.


Project To Merge Output

Easy to Use and Configure

By default all references with Copy Local equals true are merged to the project output, giving you an "ILMerged" assembly right out of the box. You can change this behavior and a lot more through an optional configuration file. For example, a static list of assemblies can be used instead of the dynamic dependency on the Copy Local property.

{
	"General": {
		"InputAssemblies": [
		  "XrmUtils.Plugins.Abstractions", 
		  "XrmUtils.Plugins.Utilities" 
		]
	}
}

Project Wiki

See the Project Wiki for more details.

ilmerge-msbuild-task's People

Contributors

ckovamees avatar davidcie avatar emerbrito avatar johannesegger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ilmerge-msbuild-task's Issues

illigael path with AssemblyFile

I install the package in vs 2019 . When installed , then console shows

C:\Users\kois\source\repos\IdCard\IdCard.csproj : error  : 元素 <UsingTask> 中“AssemblyFile”特性的值“>C:\Users\kois\.nuget\packages\msbuild.ilmerge.task\1.1.1\build\..\tools\MSBuild.ILMerge.Task.dll”无效。路径中具有非法字符。  C:\Users\kois\.nuget\packages\msbuild.ilmerge.task\1.1.1\build\MSBuild.ILMerge.Task.targets

ILMergeConfig.json is not applied

Hi,

I'm using v1.0.5 in VS 2017. I created ILMergeConfig.json in project root folder and specified InputAssembies.

When I build the project, it doesn't apply the config json file and always merge Copy Local = True assemblies.

Did I miss any step?

Improve the way ilmerge executable is located.

ILMerge nuget package 3.017 introduced a new build property (ILMergeConsolePath) that contains the executable's location (thanks to @ltrzesniewski for pointing it out in here)

We should use this property whenever available before attempting to search for the executable in a series of expected locations.

Need for UserProfile variable with ILMergeConfig.json (for using PackageReference format)

I changed all my Nuget references from the packages.config format to use the PackageReference format (https://docs.microsoft.com/en-us/nuget/reference/migrate-packages-config-to-package-reference) which offers quite a few advantages. This means that I don't have any packages folder within my VS solution or project structure to reference within my ILMergeConfig.json file. Instead I need to be able to reference the global-packages folder which generally resides here:
Windows: %userprofile%.nuget\packages
Mac/Linux: ~/.nuget/packages

Is there a config variable for UserProfile for both PC and MACs that I can use to reference my InputAssemblies and also to specify an AlternativeILMergePath in the ILMergConfig.json file?

Key needs to be greater than 0 - possible error when running task multiple times

This error in ILMerge can occur when using the build task multiple times in the same build.

In our case we had about 10 projects in a solution that needed to be merged individually. As the build task loads the ILMerge assembly once into the build process and ILMerge uses statics this can lead to the error Key needs to be greater than 0 explained in more detail in the referenced issue.

Our workarround was to turn on BuildInParallel and setting -maxcpucount > 1 which reduced the number of merge operations per msbuild process.

As

it [ILmerge] was definitely written as a console application that would run once and then terminate.

I would suggest a) allow the option to spawn a new ILMerge process per merge operation or b) load ILMerge into a secondary AppDomain and unload it after the merge or c) maybe consider a upstream fix if possible.

This issue has caused us quite some pain as builds were failing seemingly randomly so I hope someone else finds this and can save themselves some headache.

ILMerge.MSBuild.Task.targets incompatible with VS2017

It seems that we need a minor modification to the file in order for VS2017 to recognize it properly.
When loading the target file, MSBuild shipped with VS2017 complains that the %(CopyLocal) should be qualified as %(ReferencePath.CopyLocal).
There are two places in the file to which this qualification applies.
I would be glad if you could update the nuget package with this fix applied, though the fix is still possible at the project level after installing the package.
I thought it was overkill to fork the entire repository and issue a pull request just for this fix.
Thank you in advance.

Cannot find ILMerge executable

It is unable to find my ilmerge package.
Nuget packages can be stored under C:\Users%USERNAME%.nuget\packages
It might also be one level deeper under a version folder, like "packages\ilmerge\2.13.307"

Support for Xamarin.Android

Hi,

does this package supports Xamarin.android?

Im trying to merge the assemblies so I can then obfuscate them and tried this package but Im getting this error:
Error The "MergeTask" task failed unexpectedly. System.ArgumentOutOfRangeException: Unable to parse .Net framework version: v9.0 Parameter name: version at ILMerge.MsBuild.Task.FrameworkInfo.ToILmergeTargetPlatform(String version, String architecture) in D:\Dev\Github\ILMerge-MSBuild-Task\ILMerge.MSBuild.Task\ILMerge.MSBuild.Task\FrameworkInfo.cs:line 122 at ILMerge.MsBuild.Task.MergeTask.SetDefaults(MergerSettings settings) in D:\Dev\Github\ILMerge-MSBuild-Task\ILMerge.MSBuild.Task\ILMerge.MSBuild.Task\MergeTask.cs:line 250 at ILMerge.MsBuild.Task.MergeTask.Execute() in D:\Dev\Github\ILMerge-MSBuild-Task\ILMerge.MSBuild.Task\ILMerge.MSBuild.Task\MergeTask.cs:line 136 at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

Exception of type 'System.OutOfMemoryException' was thrown.

I'm using VS 2019, with .NET Core SDK 3.1.100-preview3 installed and a csproj file with the following:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <TargetFrameworks>net472</TargetFrameworks>
    <OutputType>exe</OutputType>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="ilmerge" Version="3.0.29" />
    <PackageReference Include="ILMerge.MSBuild.Task" Version="1.0.7" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Bonsai.Configuration\Bonsai.Configuration.csproj" />
    <ProjectReference Include="..\Bonsai.Design\Bonsai.Design.csproj" />
    <ProjectReference Include="..\Bonsai.Editor\Bonsai.Editor.csproj" />
    <ProjectReference Include="..\Bonsai.NuGet\Bonsai.NuGet.csproj" />
  </ItemGroup>
</Project>

The ILMergeConfig.json file constains the following:

{
  "General": {
    "InputAssemblies": [
      "NuGet.Core.dll",
      "Bonsai.NuGet.dll",
      "Bonsai.Configuration.dll"
    ]
  },
  "Advanced": {
    "ExcludeFile": "ilmerge.internalize.exclude.txt",
    "Internalize": true
  }
}

I get the following log:

6>C:\Users\antao\.nuget\packages\ilmerge.msbuild.task\1.0.7\build\ILMerge.MSBuild.Task.targets(13,5): error : ILMerge.Merge: 	There were errors reported in Bonsai's metadata.
6>C:\Users\antao\.nuget\packages\ilmerge.msbuild.task\1.0.7\build\ILMerge.MSBuild.Task.targets(13,5): error : 	Exception of type 'System.OutOfMemoryException' was thrown.

Removing the Advanced section results in the same error.

The project can be found at https://bitbucket.org/aalmada/bonsai/src/netcoreapp3.0/Bonsai/

"ILMerge.exe was no located"

I have installed ILMerge (msi installer) and this package, but when I build I get the error message "ILMerge.exe was no located".
I tried restarting Visual Studio but it did not help. What am I missing?

Delete source input assemblies

Workflow:
I'm writing a small installer that needs to be packed into one executable file to not to scare users with the number of assemblies. I don't need original assemblies after the merge.

Desire:
It would be great to be able to automatically delete them. Now I redirected the output folder to another location, and set the OutputFile property, but this does not allow using the Output directory provided by the project settings.

P.S. Thanks for the great solution!

Task fails when NuGet packages folder differs from default one

In our environment, packages are placed in different folder than in default "packages" in solution directory. Check NuGet configuration file for more info, but basically it can be set in NuGet.Config file like on example below.

<config>
	<add key="repositoryPath" value="..\_packages" />
</config>

Build output below

error MSB4018: The "MergeTask" task failed unexpectedly.
error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path 'W:\compunet.cz\Sirwisa.LogManager.WES\packages'.
error MSB4018:    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
error MSB4018:    at System.IO.FileSystemEnumerableIterator`1.CommonInit()
error MSB4018:    at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
error MSB4018:    at System.IO.Directory.EnumerateDirectories(String path, String searchPattern, SearchOption searchOption)
error MSB4018:    at ILMerge.MsBuild.Task.ExeLocationHelper.TryILMergeInSolutionDir(String solutionDir, String& executablePath) in D:\Dev\Repos\ILMerge-MSBuild-Task\ILMerge.MSBuild.Task\ILMerge.MSBuild.Task\ExeLocationHelper.cs:line 48
error MSB4018:    at ILMerge.MsBuild.Task.MergeTask.GetILMergePath() in D:\Dev\Repos\ILMerge-MSBuild-Task\ILMerge.MSBuild.Task\ILMerge.MSBuild.Task\MergeTask.cs:line 475
error MSB4018:    at ILMerge.MsBuild.Task.MergeTask.Execute() in D:\Dev\Repos\ILMerge-MSBuild-Task\ILMerge.MSBuild.Task\ILMerge.MSBuild.Task\MergeTask.cs:line 148
error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

ILMergeAllowDuplicateType doesn't seem to be working

I am using the ILMerge.props file to try and allow duplicate types in my merged assembly. I have set this value in the file to true like so

<ILMergeAllowDuplicateType>true</ILMergeAllowDuplicateType>

But that didn't do anything. I've also added an ILMergeConfig,json file and set the AllowDuplicateType property in the Advanced object to true like so

"AllowDuplicateType": true

Yet I'm still seeing this issue:

ILMerge.Merge: ERROR!!: Duplicate type 'Newtonsoft.Json.ConstructorHandling' found in assembly 'Newtonsoft.Json'. Do you want to use the /alllowDup option?

Am I missing something?

The "MergeTask" failed unexpectedly. ...

Severity	Code	Description	Project	File	Line	Suppression State
Error		The "MergeTask" task failed unexpectedly.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at ILMerge.MsBuild.Task.MergeTask.MergeAssemblies(String mergerPath, MergerSettings settings) in D:\Dev\Github\ILMerge-MSBuild-Task\ILMerge.MSBuild.Task\ILMerge.MSBuild.Task\MergeTask.cs:line 313
   at ILMerge.MsBuild.Task.MergeTask.Execute() in D:\Dev\Github\ILMerge-MSBuild-Task\ILMerge.MSBuild.Task\ILMerge.MSBuild.Task\MergeTask.cs:line 162
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	Modulus.API.Licensed			

Only changed the TargetFramework field in the .json file from null to v4.7.1. Otherwise I'm using the defaults and I get this error.

ABout box auto override by content of other dll

Dear Emerbrito,

Your dll is very good. Thanks for your help.

When I use you nuget, every dll is merged ok into one exe and the app is doing well, except for problem below.

I use NLog for tracking log in my app. When run app, this dll overide the content in my "About Box" (default form of Winform).

https://flic.kr/p/29Sp871

Can you fix this ? Thank you.

Best Regards,

Specify a custom ILMergeConfig.json file for different build configurations?

I can see that the ILMergeConfig.json is hard coded as a configuration file here:

https://github.com/emerbrito/ILMerge-MSBuild-Task/blob/master/ILMerge.MSBuild.Task/ILMerge.MSBuild.Task/build/ILMerge.MSBuild.Task.targets#L28

Would it be possible to change this to a variable that just has this by default as "ILMergeConfig.json" but it could potentially be set in the main csproj to be a different file? The reason is because we have a few different build configurations and are cross targeting so need a different ILMergeConfig.json per build configuration. Happy to help if this is possible

`AllowDuplicateTypes` is not defined in the `AdvancedSettings.cs`

I think that there is a bug in AdvancedSettings.cs.

According to the project wiki, the configuration file, in its Advanced section, is supposed to allow us to specify AllowDuplicateTypes (which is listed in the wiki reference document as having a null default value by the way, which is probably a typo, since it should be false).

However, when I look at AdvancedSettings.cs, there is no property that corresponds to AllowDuplicateTypes defined.

Automatically add TargetDir to ILMerge SearchDirectories parameter

By automatically adding $(TargetDir) to ILMerge's SearchDirectories collection, it won't be necessary to specify a path in the configuration file when we know in advance that those assemblies are in the output directory.

We should be able to use this:

{
  "General": {
    "InputAssemblies": [
      "Dependency1.dll",
      "Dependency2.dll"
    ]
  }
}

Instead of this:

{
  "General": {
    "InputAssemblies": [
      "$(TargetDir)Dependency1.dll",
      "$(TargetDir)Dependency2.dll"
    ]
  }
}

Debug info missing

When I use this tool and build my project in debug mode, the merged dll that is produced is missing the debug symbols and I cannot debut it.

Is there an easy fix for this?
I see DebugInfo property is documented to be "true" by default, but perhaps I should create a settings file and set it to true?

I'm running off the default settings, don't have a config file in my project.

Thanks!

The process cannot access the file 'bin\Debug\MyAssembly.pdb' because it is being used by another process.

Hi.

Thank you for ILMerge.MSBuild.Task.

When I try to build my assembly and there's a missing (indirect) assembly reference, I get the following error:

1>C:\MyAssembly\packages\ILMerge.MSBuild.Task.1.0.5\build\ILMerge.MSBuild.Task.targets(13,5): error : Unresolved assembly reference not allowed: MyMissingReference.

After I add the missing reference and rebuild, I get an unexpected error:

1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(3863,5): error MSB3027: Could not copy "obj\Debug\MyAssembly.pdb" to "bin\Debug\MyAssembly.pdb". Exceeded retry count of 10. Failed.
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(3863,5): error MSB3021: Unable to copy file "obj\Debug\MyAssembly.pdb" to "bin\Debug\MyAssembly.pdb". The process cannot access the file 'bin\Debug\MyAssembly.pdb' because it is being used by another process.

The issue is that a file handle to bin\Debug\MyAssembly.pdb is left open after the first build error.

As a work-around, I have to close Visual Studio, re-open the solution, and rebuild again.

Thank you.

CreateDirectory error

After setting "OutputFile" to $(OutDir)FooBar.dll and deleting the bin folder, the following error occurs:

Error		The "MergeTask" task failed unexpectedly.
System.ArgumentException: Path cannot be the empty string or all whitespace.
   at System.IO.Directory.CreateDirectory(String path)
   at ILMerge.MsBuild.Task.MergeTask.LogConfigFile(MergerSettings settings) in D:\Dev\Github\ILMerge-MSBuild-Task\ILMerge.MSBuild.Task\ILMerge.MSBuild.Task\MergeTask.cs:line 576
   at ILMerge.MsBuild.Task.MergeTask.Execute() in D:\Dev\Github\ILMerge-MSBuild-Task\ILMerge.MSBuild.Task\ILMerge.MSBuild.Task\MergeTask.cs:line 164
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	FooBar

The workaround is to specify $(ProjectDir)\\bin\\Debug\\FooBar.dll instead.

I also noticed another quirk where setting "OutputFile" to $(OutDir)\\FooBar.dll doesn't produce an error, but actually creates a folder called "$(OutDir)" in the project directory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.