Closed tomrus88 closed 2 years ago
You should not add the PackageReference
for Microsoft.DotNet.ILCompiler
as it is now a part of the SDK, which will be used whenever the PublishAot
property is set to true
. When you explicitly add the PackageReference
, you end up with duplicate Microsoft.NETCore.Native.targets
files and duplicate entries in AutoInitializedAssemblies
item group.
@MichalStrehovsky @LakshanF We probably need to add some protection for this case.
We would like to make it possible to "upgrade" the ILCompiler package that is in use by directly referencing a newer package. So the fix will be along the lines of not adding the built-in ILCompiler targets when they're already added from the package. I think IL Linker package does that too.
Let's use this issue to track that.
Cc @dotnet/ilc-contrib
@LakshanF Can you take a look at this? It will probably be necessary for your work to boostrap ILC as we may reasonably need to upgrade the version of ILC sooner than SDK updates
Describe the bug
Publishing app with NativeAOT results in broken binary.
To Reproduce
Create C# hello world console app and edit project file to be like this
Unhandled Exception: System.InvalidOperationException: Operation is not valid due to the current state of the object. at Internal.Reflection.Core.Execution.ReflectionCoreExecution.InitializeExecutionDomain(ReflectionDomainSetup, ExecutionEnvironment) + 0x94 at Internal.Reflection.Execution.ReflectionExecution.Initialize() + 0x35 at ConsoleApp5!+0x1f0d6a
--initassembly:System.Private.CoreLib --initassembly:System.Private.StackTraceMetadata --initassembly:System.Private.TypeLoader --initassembly:System.Private.Reflection.Execution --initassembly:System.Private.CoreLib --initassembly:System.Private.StackTraceMetadata --initassembly:System.Private.TypeLoader --initassembly:System.Private.Reflection.Execution