【问题标题】:Unable to add UWP target from CSProj file无法从 CSProj 文件添加 UWP 目标
【发布时间】:2020-08-04 15:30:23
【问题描述】:

我已将 uap10.0 添加到 CSProj 文件(Net Core 项目)中的目标框架列表中,以便我可以从 UWP 项目中引用此库。

如下:-

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netcoreapp1.1;net462;uap10.0;xamarin.ios10;MonoAndroid70</TargetFrameworks>
  </PropertyGroup>

</Project>

但是在构建时我收到以下错误消息:-

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(84,5): error : Cannot infer TargetFrameworkIdentifier and/or TargetFrameworkVersion from TargetFramework='uap10.0'. They must be specified explicitly.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1111,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v10.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

我做错了什么?

谢谢。

【问题讨论】:

  • 也许你想创建一个 .NET Standard 项目。
  • 听起来很明智,但我如何添加所需的参考资料。与project.json系统不同。

标签: c# uwp


【解决方案1】:

您可以通过在您的 csproj 中添加以下内容来定位 .NET Standard 1.4,这是第一个支持 uap10.0 的版本:

<PropertyGroup>
    <TargetFrameworks>netstandard1.4;net462;netcoreapp1.0</TargetFrameworks>
</PropertyGroup>

【讨论】:

  • 那行得通,而且似乎把 netstandard1.4 放在前面比放在最后效果更好..
【解决方案2】:

看起来目标框架的顺序也很重要。根据this issuenetstandard 参考应该是第一位的。在提到的链接中,问题的答案是:

我在使用 VS2019 时仍然遇到这个问题,并且从跨平台库的 UWP(目标 17763)中引用 P2P。重新启动 VS 并将 netstandard2.0 作为第一个目标修复了问题

<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>

它帮助了我,希望它可以帮助其他人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    相关资源
    最近更新 更多