gluck / il-repack

Open-source alternative to ILMerge
Apache License 2.0
1.18k stars 217 forks source link

"Specified method is not supported" on net5.0 #273

Closed aalmada closed 10 months ago

aalmada commented 4 years ago

I'm using ILRepack.MSBuild.Task 2.0.1 on .NET 5.0.100-preview.7 with target framework netstandard2.0.

I'm getting the following error when I run dotnet build on the command line:

C:\Projects\NetFabric.Hyperlinq\NetFabric.Hyperlinq.SourceGenerator\NetFabric.Hyperlinq.SourceGenerator.csproj(31,5): error : Specified method is not supported.
C:\Projects\NetFabric.Hyperlinq\NetFabric.Hyperlinq.SourceGenerator\NetFabric.Hyperlinq.SourceGenerator.csproj(31,5): error :    at Mono.Cecil.ModuleParameters.GetCurrentRuntime()
C:\Projects\NetFabric.Hyperlinq\NetFabric.Hyperlinq.SourceGenerator\NetFabric.Hyperlinq.SourceGenerator.csproj(31,5): error :    at Mono.Cecil.ModuleParameters..ctor()
C:\Projects\NetFabric.Hyperlinq\NetFabric.Hyperlinq.SourceGenerator\NetFabric.Hyperlinq.SourceGenerator.csproj(31,5): error :    at ILRepacking.ILRepack.Repack()
C:\Projects\NetFabric.Hyperlinq\NetFabric.Hyperlinq.SourceGenerator\NetFabric.Hyperlinq.SourceGenerator.csproj(31,5): error :    at ILRepack.MSBuild.Task.ILRepack.Execute()

I don't get the error when I build inside Visual Studio.

I reported the issue on Cecil (https://github.com/jbevain/cecil/issues/669) but it seems the issue is with ILRepack.

sanikolov commented 4 years ago

+1 agreed, getting the same on .net 5.0.

lextm commented 4 years ago

Related to https://github.com/gluck/il-repack/pull/236

replaysMike commented 3 years ago

bump, I believe this is fixed in Cecil now. Would be great to have an update for this as it's blocking .net 5 support for several of my packages.

replaysMike commented 3 years ago

actually, I rolled back my .Net 5 support and am still seeing the error in ILRepack 2.0.13. <TargetFrameworks>netstandard2.0;net48</TargetFrameworks>

error : Specified method is not supported.
error :    at Mono.Cecil.ModuleParameters.GetCurrentRuntime()
error :    at Mono.Cecil.ModuleParameters..ctor()
error :    at ILRepacking.ILRepack.Repack()
error :    at ILRepack.MSBuild.Task.ILRepack.Execute()
triforcely commented 3 years ago

Is there any progress on this issue?

andrei-epure-sonarsource commented 2 years ago

Is there any update?

sanikolov commented 2 years ago

I recommend the following alternative:

add this to your csproj

<PackageReference Include="ILMerge.Fody" Version="1.22.0" PrivateAssets="All" />

and then place lines like the following in the folder where the csproj lives (the filename must be FodyWeavers.xml)

<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
      <ILMerge IncludeAssemblies='foo.bar.*|Newtonsoft.Json.*|etc' />
</Weavers>

This worked for me on .NET Core all the way to 6.0 and probably beyond. I haven't tested it on any netfx version. The best part is that it allows multiple DLLs to be merged into a single DLL which the coreclr single deployment tools do NOT allow (which is ridiculous).

calwi commented 1 year ago

Any chance this can work in .net 6.0? Works fine locally in VS 2022, but get this error in Azure Devops.

vmimage: windows-latest

chejunkie commented 1 year ago

I have the exact same issue as @aalmada ILRepack 2.0.18 in .net6. I tried @sanikolov proposed workaround but it did not work for me.

Edit: I should also mention to be clearer, that building from VS2022 succeeds and I can see the two name spaces when opening the combined DLL in a decompiler (e.g., dotPeek), but VS cannot pickup the methods in the combined DLL. I then attempted to dotnet build the project, which is when I got the same errors:

Build FAILED.

.csproj(31,5): error : Specified method is not supported. .csproj(31,5): error : at Mono.Cecil.ModuleParameters.GetCurrentRuntime() .csproj(31,5): error : at Mono.Cecil.ModuleParameters..ctor() .csproj(31,5): error : at ILRepacking.ILRepack.Repack() .csproj(31,5): error : at ILRepack.MSBuild.Task.ILRepack.Execute() 0 Warning(s) 1 Error(s)

Line 31 from the project file shows ILRepack is not understood?

<ILRepack OutputType="$(OutputType)" MainAssembly="$(AssemblyName).dll" OutputAssembly="$(AssemblyName).dll" InputAssemblies="@(InputAssemblies)" InternalizeExcludeAssemblies="@(InternalizeExcludeAssemblies)" WorkingDirectory="$(WorkingDirectory)" />

The project is referencing ILRepack.MSBuild.Task 2.0.13, but I also tried earlier versions with the same result but different error message:

error MSB4036: The "ILRepack" task was not found. Check the following: 1.) The nam e of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with in the project file, or in the *.tasks files located in the "C:\Program Files\dotnet\sdk\7.0.201" directory.

chejunkie commented 1 year ago

I could not get ILRepack to work, but there was a more recent nuget that did the trick:

https://www.nuget.org/packages/ILRepack.Lib.MSBuild/2.1.18/

However, VS2022 still will not recognize the different DLL namespaces that were merged although dotPeek has no problem reading them and their contents.

EDIT: I eventually got VS2022 to recognize the merged namespaces. In my case, it has something to do with the new console template for .net6 that uses top level statements. As soon as I went back to the old style, with a Program class and Main method, VS2022 was able to pickup the merged name spaces and their contents correctly in the console app I was using for testing.

This other repack also works:

https://github.com/ravibpatel/ILRepack.Lib.MSBuild.Task

(It is a little nicer, in my opinion, as you are able to modify targets and post build task.)

aalmada commented 1 year ago

Any chance this can work in .net 6.0? Works fine locally in VS 2022, but get this error in Azure Devops.

vmimage: windows-latest

I have the same issue with GitHub Actions. It works fine locally using ILRepack.MSBuild.Task on Visual Studio 2022.

Action report: https://github.com/NetFabric/NetFabric.Hyperlinq.Analyzer/actions/runs/5542153526/jobs/10116466992?pr=66

KirillOsenkov commented 10 months ago

This should work fine with the latest ILRepack version: https://www.nuget.org/packages/ILRepack/2.0.23