gpt4 book ai didi

xamarin - 无法在 Release模式下使用 StructureMap 编译 Xamarin android 项目

转载 作者:行者123 更新时间:2023-12-02 17:21:01 28 4
gpt4 key购买 nike

在 Visual Studio 中创建一个空白 Android 项目空白应用程序 (Android),然后添加以下 nuget 包
NETStandard.Library 1.6.1
结构图4.5.2

现在尝试在 Release模式下编译项目。我收到以下错误:

Using "LinkAssemblies" task from assembly "C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll".
Task "LinkAssemblies"
LinkAssemblies Task
UseSharedRuntime: False
MainAssembly: obj\Release\linksrc\App2.dll
OutputDirectory: obj\Release\android\assets\
OptionalDestinationDirectory:
I18nAssemblies:
LinkMode: SdkOnly
LinkSkip:
LinkDescriptions:
ResolvedAssemblies:
obj\Release\linksrc\App2.dll
obj\Release\linksrc\Java.Interop.dll
obj\Release\linksrc\Mono.Android.dll
obj\Release\linksrc\System.Core.dll
obj\Release\linksrc\System.dll
obj\Release\linksrc\System.IO.Compression.dll
obj\Release\linksrc\System.Net.Http.dll
obj\Release\linksrc\System.Xml.dll
obj\Release\linksrc\mscorlib.dll
obj\Release\linksrc\StructureMap.dll
obj\Release\linksrc\System.Runtime.Loader.dll
obj\Release\linksrc\System.Runtime.dll
obj\Release\linksrc\System.ComponentModel.Composition.dll
obj\Release\linksrc\System.Threading.dll
obj\Release\linksrc\System.Collections.dll
obj\Release\linksrc\System.Collections.Concurrent.dll
obj\Release\linksrc\System.Reflection.dll
obj\Release\linksrc\System.Diagnostics.Debug.dll
obj\Release\linksrc\System.Linq.dll
obj\Release\linksrc\System.Runtime.InteropServices.dll
obj\Release\linksrc\System.Runtime.Extensions.dll
obj\Release\linksrc\System.Reflection.Extensions.dll
obj\Release\linksrc\System.Runtime.Serialization.dll
obj\Release\linksrc\System.ServiceModel.Internals.dll
obj\Release\linksrc\Mono.Security.dll
obj\Release\linksrc\System.Resources.ResourceManager.dll
obj\Release\linksrc\System.IO.dll
obj\Release\linksrc\System.Threading.Tasks.dll
obj\Release\linksrc\System.Linq.Expressions.dll
obj\Release\linksrc\System.Reflection.Emit.Lightweight.dll
obj\Release\linksrc\System.Reflection.Emit.ILGeneration.dll
obj\Release\linksrc\System.Reflection.TypeExtensions.dll
obj\Release\linksrc\System.Reflection.Primitives.dll
obj\Release\linksrc\System.Globalization.dll
obj\Release\linksrc\System.AppContext.dll
obj\Release\linksrc\System.IO.FileSystem.dll
obj\Release\linksrc\System.Console.dll
EnableProguard: False
ProguardConfiguration:
DumpDependencies: False
LinkOnlyNewerThan:
HttpClientHandlerType:
TlsProvider:
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly.
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: Mono.Linker.MarkException: Error processing method: 'System.Boolean StructureMap.Graph.AssemblyFinder/<FindAssemblies>
d__1::MoveNext()' in assembly: 'StructureMap.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Runtime.Loader.AssemblyLoadContext System.Runtime.Loader.AssemblyLoadContext::get_Default()
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessQueue()
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: --- End of inner exception stack trace ---
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessQueue()
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Mono.Linker.Steps.MarkStep.Process()
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Mono.Linker.Pipeline.Process(LinkContext context)
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute()
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
Done executing task "LinkAssemblies" -- FAILED.
Done building target "_LinkAssembliesShrink" in project "App2.csproj" -- FAILED.

Build FAILED.

在 Debug模式下,它按预期进行编译,但我猜 LinkAssemblies 任务不会运行。

我使用的是 Xamarin 4.6.0.297 和 Visual Studio 2015。

这是 StructureMapXamarin 中的问题吗?

最佳答案

更新:

这似乎是链接器和不同版本的 NetStandard 库的问题。 StructureMap 在 nuget 中设置为支持 .Net45、NetStandard 1.3 和 NetStandard 1.5,添加 NetStandard Lib 1.6 后,除非您将软件包更新到 NetStandard Lib 2.0(及其匹配的库),您将收到 Mono.Cecil 错误:

Mono.Cecil.ResolutionException: Failed to resolve System.Runtime.Loader.AssemblyLoadContext System.Runtime.Loader.AssemblyLoadContext::get_Default()

注意:我不确定这是否是 Mono.Cecil 的问题、StructureMap 的打包方式或 Xamarin 处理 nuget 引用的方式...

链接描述:

像下面这样的链接器配置可以帮助您解决这个问题:

<linker>
<assembly fullname="StructureMap">
<namespace fullname="StructureMap.*" />
</assembly>
</linker>

只需将包含上述内容的 XML 文件添加到您的项目中,然后为其分配 LinkDescription 构建操作即可。

注意:使用 AndroidLinkSkip 跳过程序集不起作用...

关于xamarin - 无法在 Release模式下使用 StructureMap 编译 Xamarin android 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45812866/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com