【发布时间】:2016-02-08 19:08:12
【问题描述】:
我正在开发一个用于 WPF 和 Windows 10 的库。我遇到了让它在后者上编译的问题。以下是部分代码:
project.json
{
"frameworks": {
"net46": {
"frameworkAssemblies": {
"WindowsBase": "4.0.0.0"
}
},
"netcore50": {
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
}
}
}
}
Dependency.cs
using System;
using System.Collections.Generic;
#if NET46
using System.Windows; // .NET Framework 4.6
#elif NETCORE50
using Windows.UI.Xaml; // Windows 10 apps
#endif
public static class Dependency
{
public static DependencyProperty Register<T, TOwner>(string name, PropertyChangedCallback<T, TOwner> callback)
where TOwner : DependencyObject
{
// Code here....
}
}
虽然这对于 net46(这是传统的 .NET 框架)编译得很好,但我无法让它为 netcore50(可用于 Windows 10 应用程序)工作。出于某种原因,该配置中似乎不包含 DependencyProperty 或 DependencyObject 之类的类型。
我是否可以安装包含这些类型的netcore50 兼容 NuGet 包,以便我可以从我的库中使用它们?
感谢您的帮助。
编辑:我刚刚在 VS 中输入 DependencyProperty 并按 F12。该类型似乎存在于 Windows.Foundation.UniversalApiContract 程序集中,但 NuGet 上没有这样的包。
【问题讨论】:
-
很确定这是不可能的——像 WPF 这样的东西并不打算跨平台 afaik,不过如果你感兴趣的话,你可以看看像 Perspex 这样的项目。
-
@Warty 我认为你可以 - .NET Core 并不意味着你只能创建与平台无关的库,这意味着可以创建它们。例如你仍然可以使用像
Microsoft.Win32.Registry这样的包。
标签: c# asp.net .net windows-runtime asp.net-core