0
votes

I have some code in a Universal Windows class library I want to use from a .NET core project.

I have a pi running Windows IOT for which I installed adafruits PWM hat. I have found an UWP project containing the needed C# code and that works great.

But at the pi I also want to have an asp.net core project that uses the UWP project. But if I add a reference from my asp.net core to UWP it tells that it is not supported which also make sense as they are at same level in the .net architecture.

I use Visual Studio 2019 and just installed .NET Core 3.0 preview3.

Any way I can achive to use the UWP from my core project?

2
You can only cut and paste. blog.lextudio.com/… - Lex Li
I'm not familiar with UWP, but the code you have in your class library, is it ties to UWP stuff? Can you port the class library to target .NET Standard? Then you can reference it in all projects. - jpgrassi
Unfortunately it use UWP stuff like: Windows.Devices.I2c so not easy to port - JerryA
@JerryA: How are you supposed to use UWP specific stuff in an ASP.NET Core app? Code that makes sense to share between different platforms should target .NET Standard. - mm8
@mm8 - yes, you are right. As you can see in below that also what I ended up with. - JerryA

2 Answers

1
votes

If you want to reference, it can't be done as you said yourself it makes no sense.

Some workaround would be to move the code from UWP project to the new .Net Core project and then reference it from both projects. If you use some UWP APIs you might consider to use a shared project with conditional compiling instead of the new .Net Core project.

0
votes

Try adding

    <ItemGroup>
        <PackageReference Include="System.Runtime.WindowsRuntime" Version="4.6.0-preview4.19212.13" />
        <Reference Include="Windows">
            <HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd</HintPath>
        </Reference>
    </ItemGroup>

to your csproj file. It allowed me to use UWP api in asp.net core preview 3 project.