gluck / il-repack

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

Failed to find target platform 'v4' #371

Closed leppie closed 2 months ago

leppie commented 2 months ago

I am trying to change a .NET 2 exe to .NET 4, but getting the error below. Works with ILMerge.

Seems there is a TargetPlatformDirectory option, but not exposed.

System.ArgumentException: Failed to find target platform 'v4' in 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App'
   at ILRepacking.ILRepack.ResolveTargetPlatformDirectory(String version) in /_/ILRepack/ILRepack.cs:line 244
   at ILRepacking.ILRepack.ResolveSearchDirectories() in /_/ILRepack/ILRepack.cs:line 608
   at ILRepacking.ILRepack.RepackCore(String tempOutputDirectory) in /_/ILRepack/ILRepack.cs:line 333
   at ILRepacking.ILRepack.Repack() in /_/ILRepack/ILRepack.cs:line 295
   at ILRepacking.Application.Main(String[] args) in /_/ILRepack/Application.cs:line 49
KirillOsenkov commented 2 months ago

any chance you could include a zip with the repro and a cmd file that has the exact command line that you use?

leppie commented 2 months ago

Here you go. I have also include the possible locations where .NET Framework stuff lives on my PC.

ilrepack-371.zip

KirillOsenkov commented 2 months ago

Hmm when I try this, it works fine.

I'm running the desktop, 64-bit version of ILRepack.exe (the one we ship). typeof(string).Assembly.Location resolves to C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll

image

Could you be running the .NET Core version? The .NET Core version is primary for cross-plat support and I don't think it will properly support desktop framework.

leppie commented 2 months ago

Could you be running the .NET Core version? The .NET Core version is primary for cross-plat support and I don't think it will properly support desktop framework.

Yes, I am running the dotnet tool.

And it is unfortunate, because I am specifically working on cross-platform build/packaging support.

Will find some other solution.

KirillOsenkov commented 2 months ago

Have you tried passing the targetplatform? https://github.com/gluck/il-repack/blob/2c3a69e91943ebcffba49a98a4ba9e547e71ccd3/ILRepack/RepackOptions.cs#L240

maybe if you pass both the desktop directory and v4 it will work then?

leppie commented 2 months ago

Yes, I tried a few things.

In the end, I only needed to indicate the .NETFramework runtime.

Just wrote something quick in cecil (that works for my use case).

https://github.com/IronScheme/IronScheme.BuildTools/blob/master/RuntimeChanger/RuntimeChanger.cs