微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果使用条件目标框架,Nuget 会为错误的目标框架恢复包

如何解决如果使用条件目标框架,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 进行了恢复。有没有办法为 nuget restore 指定 targetFramework?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。