.net-core - 如果使用条件目标框架,Nuget 会为错误的目标框架恢复包
问题描述
我有一个解决方案,它通过选择相应的配置来构建 .NetFramework 3.5 或 .NetFramework 4.5.2 库。我正在尝试将其迁移到 .NET5,但我也想保留构建 .NetFramework 库的可能性。因为该解决方案包含一些不支持多目标的 CLI/C++ 项目,所以我决定使用条件 TargetFrameworks:
<PropertyGroup Condition=" '$(Configuration)' == 'Debug_Net5' Or '$(Configuration)' == 'Release_Net5' ">
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug_Net4' Or '$(Configuration)' == 'Release_Net4' ">
<TargetFramework>net452</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' Or '$(Configuration)' == 'Release' ">
<TargetFramework>net35</TargetFramework>
该解决方案由 Visual Studio 成功构建。但是,如果我尝试将 MSBuild 用于构建前言,Nuget restore
请致电:
"nuget.exe" restore <mySolutionPath> -Verbosity detailed
msbuild <mySolutionPath> /p:Configuration=Debug_Net4;Platform=x86
我收到错误:
C:\Program Files\dotnet\sdk\5.0.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: Assets file '<projectpath>\obj\project.assets.json' doesn'
t have a target for 'net452'. Ensure that restore has run and that you have included 'net452' in the TargetFrameworks for your project.
根据nuget restore
输出和资产文件内容,仅对 .NetFramework 3.5 进行了恢复。有什么方法可以指定 targetFrameworknuget restore
吗?
解决方案
推荐阅读
- java - React Native 自定义文本选择菜单
- sockets - 当一个进程试图读取比发送它的字节更多的字节时会发生什么
- sql - 我如何设计一个数据库系统来跟踪客户订单和运输信息
- node.js - 如何在mongodb中存储哈希密码
- python - Pytest with Moto,使用后端更改 athena 查询的状态
- visual-studio - Visual Studio C++ CMake 错误:找不到 wxWidgets(缺少:gl)
- selenium - 使用 Selenium 获取要单击的元素时遇到问题
- vue.js - 如何从子组件更改父数据?
- php - 在 Oauth2 中使用 Ion Auth BCrypt
- r - 在 ggplot 中添加文本 - ggplot 中每个图右上角的点数