netCore程序发布到生产环境时出现了这么一个错误
NETSDK1061错误解决
- 在vs生成和运行都正常,发布的时候报错
- .netcore控制台项目引用另一个类库
- 错误信息
NETSDK1061: 项目是使用 Microsoft.NETCore.App 版本 2.1.14 还原的, 但使用当前设置, 将改用版本 2.1.0。要解决此问题, 请确保将相同的设置用于还原和后续操作 (如生成或发布)。通常, 如果 RuntimeIdentifier 属性是在生成或发布过程中设置的, 而不是在还原过程中进行的, 则会发生此问题。有关详细信息, 请参阅 https://aka.ms/dotnet-runtime-patch-selection
解决办法
- 在出异常的项目属性里面的<PropertyGroup>节点加上的
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>,直接编辑.csproj就可以了
- 有关说明
- 大概意思是说,正常使用命令restore还原包的时候会选择最新的程序版本,发布的时候命令restore被隐式调用,不能使用最新的版本,两者版本不一致就会报错。将
TargetLatestRuntimePatch
属性设置为 true就避免在发布的时候还原