c# - How to use Windows Runtime classes in .NET Core libraries? -


i'm developing library use wpf , windows 10. i'm running issues getting compile on latter. here of code:

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)         towner : dependencyobject     {         // code here....     } } 

while compiles fine net46 (which traditional .net framework), i'm having trouble getting work netcore50 (which can used windows 10 apps). reason, looks types dependencyproperty or dependencyobject not included in configuration.

is there netcore50-compatible nuget package can install contains these types, can use them library?

thanks helping.


edit: typed in dependencyproperty in vs , hit f12. appears type lives in windows.foundation.universalapicontract assembly, there's no such package on nuget.

finally solved problem on own! (if you're looking quick answer, may want scroll down.)

i remembered chance .net core github repo had bunch of winrt-specific libraries, system.runtime.windowsruntime. so, headed on there see how did it.

it appears use kind of internally-hosted "targeting pack", contains single windows.winmd file (which holds types in windows runtime), achieve affect. unfortunately, package hosted on private nuget feed meant .net core team, can't use it.

i've opened issue on corefx repo here, can petition microsoft official solution problem. in meantime, i've taken matters own hands. i've found different versions of windows.winmd on laptop, , uploaded them nuget packages. here are:

you can use them this:

"frameworks": {     ".netportable,version=v4.5,profile=profile32": {         "dependencies": {             "target.windowsruntime": "8.1.2"         }     } } 

after that, you'll able write this:

using windows.ui.xaml; using windows.ui.xaml.controls;  public class myapp : application {     public myapp()     {         var button = new button();         button.content = "hello, world!";     } } 

and it'll work.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -