简体   繁体   English

引用.NET核心项目中的UWP项目

[英]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. 我想在.NET核心项目中使用通用Windows类库中的一些代码。

I have a pi running Windows IOT for which I installed adafruits PWM hat. 我有一个运行Windows IOT的pi,为此我安装了adafruits PWM帽子。 I have found an UWP project containing the needed C# code and that works great. 我发现一个包含所需C#代码的UWP项目 ,效果很好。

But at the pi I also want to have an asp.net core project that uses the UWP project. 但是在pi上,我也想有一个使用UWP项目的asp.net核心项目。 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. 但是,如果我从我的asp.net核心添加对UWP的引用,它表明它不受支持,这也很有意义,因为它们在.net体系结构中处于同一级别。

I use Visual Studio 2019 and just installed .NET Core 3.0 preview3. 我使用Visual Studio 2019并刚刚安装了.NET Core 3.0 Preview3。

Any way I can achive to use the UWP from my core project? 从我的核心项目中可以使用UWP吗?

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. 一些解决方法是将代码从UWP项目移至新的.Net Core项目,然后从两个项目中引用它。 If you use some UWP APIs you might consider to use a shared project with conditional compiling instead of the new .Net Core project. 如果使用某些UWP API,则可以考虑使用带条件编译的共享项目,而不是新的.Net Core项目。

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. 到您的csproj文件。 It allowed me to use UWP api in asp.net core preview 3 project. 它允许我在asp.net核心预览3项目中使用UWP api。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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