- 
        Couldn't load subscription status. 
- Fork 5.2k
Description
Description
The Microsoft.NET.ILLink.Tasks NuGet in .NET 8 preview 1 does not target .NET 8, causing problems for custom linker steps when they are built with .NET 8.
Reproduction Steps
Follow the instructions here: https://gist.github.com/jonathanpeppers/99961b4639823206c2537c03c856b097, except:
- Install a later version of the .NET 8 preview 1
- Make sure .NET 7 is installed too.
Create a new maui project and try to build it:
$ dotnet new maui
$ dotnet build -f net8.0-iosExpected behavior
Successful build.
Actual behavior
Build failure:
Fatal error in IL Linker
  Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
   ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Collections, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.   File name: 'System.Collections, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
     at MonoTouch.Tuner.CoreTypeMapStep..ctor()
     at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
     --- End of inner exception stack trace ---
     at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
     at Mono.Linker.Driver.AddCustomStep(Pipeline pipeline, String arg)
     at Mono.Linker.Driver.SetupContext(ILogger customLogger)
     at Mono.Linker.Driver.Run(ILogger customLogger)
     at Mono.Linker.Driver.Main(String[] args)
/Users/dmo/.nuget/packages/microsoft.net.illink.tasks/8.0.100-1.23067.1/build/Microsoft.NET.ILLink.targets(133,5): error MSB6006: "dotnet" exited with code 134. [/Users/dmo/work/CrazyEights/CrazyEights.csproj::TargetFramework=net8.0-ios]
/Users/dmo/.nuget/packages/microsoft.net.illink.tasks/8.0.100-1.23067.1/build/Microsoft.NET.ILLink.targets(86,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. [/Users/dmo/work/CrazyEights/CrazyEights.csproj::TargetFramework=net8.0-ios]
Regression?
Yes
Known Workarounds
Remove .NET 7.
Configuration
.NET 8.0.100-preview.1.23115.2
Other information
It's because this NuGet: https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet8/NuGet/Microsoft.NET.ILLink.Tasks/versions/8.0.100-1.23067.1 is built for .NET 7:
$ unzip -l /Users/rolf/Downloads/microsoft.net.illink.tasks.8.0.100-1.23067.1.nupkg
Archive:  /Users/rolf/Downloads/microsoft.net.illink.tasks.8.0.100-1.23067.1.nupkg
  Length      Date    Time    Name
---------  ---------- -----   ----
      520  01-17-2023 18:35   _rels/.rels
      977  01-17-2023 18:35   Microsoft.NET.ILLink.Tasks.nuspec
    39872  01-17-2023 18:35   tools/net472/ILLink.Tasks.dll
   421328  01-17-2023 18:34   tools/net472/Mono.Cecil.dll
    20856  02-19-2020 10:05   tools/net472/System.Buffers.dll
   189312  10-19-2020 18:37   tools/net472/System.Collections.Immutable.dll
   141184  02-19-2020 10:05   tools/net472/System.Memory.dll
   115856  05-15-2018 13:29   tools/net472/System.Numerics.Vectors.dll
   462728  10-19-2020 18:45   tools/net472/System.Reflection.Metadata.dll
    16768  10-19-2020 18:46   tools/net472/System.Runtime.CompilerServices.Unsafe.dll
   721296  01-17-2023 18:35   tools/net7.0/illink.dll
    40376  01-17-2023 18:35   tools/net7.0/ILLink.Tasks.dll
   421328  01-17-2023 18:34   tools/net7.0/Mono.Cecil.dll
   103888  01-17-2023 18:35   tools/net7.0/Mono.Cecil.Pdb.dll
     6822  01-17-2023 18:35   tools/net7.0/illink.deps.json
      324  01-17-2023 18:35   tools/net7.0/illink.runtimeconfig.json
    24890  01-17-2023 18:35   tools/net7.0/ILLink.Tasks.deps.json
      783  01-17-2023 18:33   Sdk/Sdk.props
     1451  01-17-2023 18:33   build/Microsoft.NET.ILLink.Tasks.props
    21256  01-17-2023 18:33   build/Microsoft.NET.ILLink.targets
    10806  01-17-2023 18:33   build/6.0_suppressions.xml
     7006  12-30-2022 18:15   Icon.png
      787  01-17-2023 18:35   [Content_Types].xml
      664  01-17-2023 18:35   package/services/metadata/core-properties/c7cfde231f344fc9b00bdaf0b59aea91.psmdcp
    11403  01-17-2023 10:38   .signature.p7s
---------                     -------
  2782481                     25 filesand our custom linker steps are built using .NET 8, thus things go wrong when the .NET 7 version of illink.dll (running on .NET 7) tries to load the custom linker steps built with .NET 8 (and this is also why having .NET 7 installed is required to reproduce the problem: if .NET 7 is not installed, illink.dll will be executed with .NET 8, and everything works).