.Net6 WPF 应用程序的 PublishReadyToRun 问题

PublishReadyToRun issue with .Net6 WPF application

我在 .Net6 WPF 应用程序中使用 PublishReadyToRun 时遇到问题。

我使用这个命令发布:

dotnet publish sources/xxx.csproj --configuration Release --framework net6.0-windows --runtime win-x64 --output output/release64/net6.0-windows/publish -p:PublishReadyToRun=true --self-contained

这里是错误:

C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error : Error: Read out of bounds. [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error : System.BadImageFormatException: Read out of bounds. [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at System.Reflection.Throw.OutOfBounds() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at System.Reflection.Metadata.Ecma335.TypeRefTableReader.GetResolutionScope(TypeReferenceHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at System.Reflection.Metadata.TypeReference.get_ResolutionScope() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.ResolveTypeReference(TypeReferenceHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(EntityHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.GetObject(EntityHandle handle, NotFoundBehavior notFoundBehavior) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.ResolveTypeReference(TypeReferenceHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(EntityHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.GetObject(EntityHandle handle, NotFoundBehavior notFoundBehavior) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at Internal.TypeSystem.Ecma.EcmaModule.GetType(EntityHandle handle) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.ReadyToRunCompilationModuleGroupBase.TryGetModuleTokenForExternalType(TypeDesc type, ModuleToken& token) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ModuleTokenResolver.GetModuleTokenForType(EcmaType type, Boolean throwIfNotFound) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.SignatureContext.GetTargetModule(TypeDesc type) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.TypeFixupSignature.GetData(NodeFactory factory, Boolean relocsOnly) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ImportSectionNode.MaterializeSignature(NodeFactory r2rFactory) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ImportSectionsTableNode.MaterializeSignature() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ManifestMetadataTableNode.ComputeLastSetOfModuleIndices() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ManifestMetadataTableNode.GetManifestAssemblyMvidTableData() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.ManifestAssemblyMvidHeaderNode.GetData(NodeFactory factory, Boolean relocsOnly) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.EmitPortableExecutable() [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Program.RunSingleCompilation(Dictionary`2 inFilePaths, InstructionSetSupport instructionSetSupport, String compositeRootPath, Dictionary`2 unrootedInputFilePaths, HashSet`1 versionBubbleModulesHash, CompilerTypeSystemContext typeSystemContext) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Program.Run(String[] args) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Program.Main(String[] args) [C:\xxx.csproj]
C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(351,5): error NETSDK1096: Optimizing assemblies for performance failed. You can either exclude the failing assemblies from being optimized, or set the PublishReadyToRun property to false. [C:\xxx.csproj]

Verbosity detailed 没有提供有关该问题的更多详细信息。

我尝试创建一个新的 net6 wpf 项目并使用这个我没有问题。

我的应用程序有很多程序集并且有本地依赖项。

有办法解决这个问题吗? crossgen2 有什么已知的限制吗?

终于在详细的啰嗦中找到了解决方案

它在依赖程序集的 crossgen2 启动中出错。

我在 csproj 中添加了一个 PublishReadyToRunExclude 节点来解决问题:

<ItemGroup>
    <PublishReadyToRunExclude Include="xxx.dll;yyy.dll" />
</ItemGroup>