我想把一個配置文件在我的IOS/Android應用程序的PCL部分。Xamarin便攜式配置文件使用PCLAppConfig
在文檔:https://github.com/mrbrl/PCLAppConfig 提示:
Assembly assembly = typeof(App).GetTypeInfo().Assembly;
ConfigurationManager.AppSettings = new ConfigurationManager(assembly.GetManifestResourceStream("DemoApp.App.config")).GetAppSettings;
我希望DemoApp是他們的示例應用程序的組件名稱,所以我必須:
使用PCLAppConfig;
namespace LYG
{
public class App : Application
{
public App()
{
Assembly assembly = typeof(App).GetTypeInfo().Assembly;
ConfigurationManager.AppSettings = new ConfigurationManager(assembly.GetManifestResourceStream("LYG.App.config")).AppSettings;
}
...
}
}
我得到以下編譯錯誤:
/Users/greg/Projects/LYG/LYG/LYG.cs(122,122):錯誤CS1061:類型PCLAppConfig.ConfigurationManager' does not contain a definition for
GetAppSettings',沒有擴展方法GetAppSettings' of type
PCLAppConfig。 ConfigurationManager'可以找到。您是否缺少裝配參考? (CS1061)(LYG)
這是我packages.config文件:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="PCLAppConfig" version="0.3.1" targetFramework="portable45-net45+win8+wp8" />
<package id="PCLStorage" version="1.0.2" targetFramework="portable45-net45+win8+wp8" />
<package id="Xamarin.Forms" version="2.3.2.127" targetFramework="portable45-net45+win8+wp8" />
</packages>
我也試圖與括號:
ConfigurationManager.AppSettings = new ConfigurationManager(assembly.GetManifestResourceStream("LYG.App.config")).AppSettings();
爲什麼不能GetAppSettings找到?