C# 无法解决引用:Android应用中的“Windows .Fase.UnvialSalpChanToupe”
在我针对UWP、Android和iOS的Xamarin.Forms应用程序中(暂时卸载),我添加了以下代码:C# 无法解决引用:Android应用中的“Windows .Fase.UnvialSalpChanToupe”,c#,android,xamarin.forms,C#,Android,Xamarin.forms,在我针对UWP、Android和iOS的Xamarin.Forms应用程序中(暂时卸载),我添加了以下代码: StorageFolder localFolder = ApplicationData.Current.LocalFolder; databasePath = Path.Combine(localFolder.Path, databaseName); public class DeviceService { private const string databaseN
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
databasePath = Path.Combine(localFolder.Path, databaseName);
public class DeviceService
{
private const string databaseName = "eTabber.db";
public static string StoragePath { get; set; }
/// <summary>
/// Return the device specific database path for SQLite
/// </summary>
public static string GetSQLiteDatabasePath()
{
return Path.Combine(StoragePath, databaseName);
}
}
这导致在.Net标准库中添加了一个参考,如下所示
<Reference Include="Windows.Foundation.UniversalApiContract">
<HintPath>..\..\..\..\..\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.UniversalApiContract\5.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
</Reference>
我确实需要对Windows.Storage的引用,以便能够在UWP应用程序中找到本地存储的正确路径。我该如何解决这个问题呢?好的,如果你知道怎么做就很容易了。该引用不应位于主.Net标准库中,而应位于UWP应用程序中。所以我做了下面的事情 在主.Net标准库中的DeviceService中,我创建了以下代码:
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
databasePath = Path.Combine(localFolder.Path, databaseName);
public class DeviceService
{
private const string databaseName = "eTabber.db";
public static string StoragePath { get; set; }
/// <summary>
/// Return the device specific database path for SQLite
/// </summary>
public static string GetSQLiteDatabasePath()
{
return Path.Combine(StoragePath, databaseName);
}
}
MainActivity.cs中的Android(尚未对此进行测试):
Main.cs中的iOS(尚未测试):
至少对于UWP来说,这种构造工作得很好。已从.Net标准库中删除引用,错误消失。已确认。在Android上也能工作。
protected override void OnCreate(Bundle savedInstanceState)
{
DeviceService.StoragePath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
...
static void Main(string[] args)
{
DeviceService.StoragePath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);