Xamarin包引用了.net标准项目内容

问题描述 投票:0回答:1

我有一个Xamarin iOS应用程序。 iOS应用程序引用另一个项目,即.NET标准项目。该项目构建了一些资源(程序集输出可忽略不计)。这些资源就是.NET标准中的内容。 iOS应用程序引用此.NET标准库。

构建iOS应用程序时,.ipa文件不包含引用程序集中的内容。

我已经尝试过各种各样的东西,比如攻击BundleResource来包含文件路径,但它没有效果,因为我无法获得新的<ProjectReference>格式来给我输出内容的文件路径,只是程序集。

如何在我的iOS应用程序中捆绑.NET Standard程序集中的内容?

ios xamarin .net-standard
1个回答
0
投票

例如,如果MyClass是一个类,MyContent.txt是一个带有属性构建操作Embeddeded resource的文本文件,两者都在.NET程序集MyAssembly.NETStandard中,在iOS程序集中(iOS应用程序):

var assembly = typeof(MyClass).GetTypeInfo().Assembly;
var filename = "MyAssembly.NETStandard.MyContent.txt";
var stream = assembly.GetManifestResourceStream(filename);
var text = "";
using (var reader = new System.IO.StreamReader(stream)) {
    text = reader.ReadToEnd();
}

必须在iOS程序集中引用.NET标准程序集MyAssembly.NETStandard

另见Loading Files Embedded as Resources

© www.soinside.com 2019 - 2024. All rights reserved.