ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

Decompile multiple projects under single solution and use ProjectReference's

Open gerneio opened this issue 3 years ago • 0 comments

Steps to reproduce

  1. Use either a) the ILSpy WPF desktop app, or b) ILSpyCmd w/ 8.0 prev 1 (CLI requires #2364 to support multiple assemblies)
  2. Make sure you have at least two DLL's where one of them has a dependency on the other (i.e. First.dll depends on Second.dll)
  3. Using CLI in terminal, execute command: ilspycmd First.dll Second.dll -p -o TEMP
  4. Open the newly generated solution in VS from the TEMP directory
  5. Notice in project First how the reference to Second is a DLL reference, NOT a project reference.

Expectation

  • First should see Second as a project reference

Details

The main culprit of this issue is in ICSharpCode.Decompiler.Solution.SolutionCreator with the use of ProjectFileNamespace which is coded for how this would work with the old project file structure.

https://github.com/icsharpcode/ILSpy/blob/94982b5368c46f58f0af2bdbd3ba300574e0f8e4/ICSharpCode.Decompiler/Solution/SolutionCreator.cs#L32

https://github.com/icsharpcode/ILSpy/blob/94982b5368c46f58f0af2bdbd3ba300574e0f8e4/ICSharpCode.Decompiler/Solution/SolutionCreator.cs#L163-L165

https://github.com/icsharpcode/ILSpy/blob/94982b5368c46f58f0af2bdbd3ba300574e0f8e4/ICSharpCode.Decompiler/Solution/SolutionCreator.cs#L176-L193

Since the new SDK style is used by default (from CLI or UI), our only option is to manually correct this after decompilation, which is a ton of work. From some quick testing, simply using string.Empty in replace of the XML namespace works just fine for the expected behavior to work. However, the correct solution would probably involve finding a way to pull in ICSharpCode.Decompiler.DecompilerSettings into SolutionCreator somehow so that we can reference the UseSdkStyleProjectFormat boolean.

https://github.com/icsharpcode/ILSpy/blob/94982b5368c46f58f0af2bdbd3ba300574e0f8e4/ICSharpCode.Decompiler/DecompilerSettings.cs#L1868

The only public method of that class is one of the WriteSolutionFile overloads...

https://github.com/icsharpcode/ILSpy/blob/94982b5368c46f58f0af2bdbd3ba300574e0f8e4/ICSharpCode.Decompiler/Solution/SolutionCreator.cs#L43

...which seems to be referenced in two different areas: ICSharpCode.ILSpyCmd.ILSpyCmdProgram.OnExecute & ICSharpCode.ILSpy.SolutionWriter.CreateSolution.

https://github.com/icsharpcode/ILSpy/blob/94982b5368c46f58f0af2bdbd3ba300574e0f8e4/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs#L137

https://github.com/icsharpcode/ILSpy/blob/94982b5368c46f58f0af2bdbd3ba300574e0f8e4/ILSpy/SolutionWriter.cs#L124

Workaround

  • I don't see any workarounds at the momment, so I think this will ultimately require a code fix.

gerneio avatar Dec 23 '22 23:12 gerneio