简体   繁体   中英

Reference a UWP project from a .NET core project

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM