我已经用targetframework Netstandard 2.0创建了一个私有的nuget包,这个包依赖于EntityFrameworkCore和EntityFramework.DbContextScope。
如果我在.Net核心项目中使用它,而不是在.net Framework4.6.1项目中使用它,则可以很好地工作。
程序包EntityFramework.DbContextScope导致了这些问题。我查看了nuget中的源代码,并在project.json中看到了以下内容
"frameworks": {
"netstandard1.3": {
"imports": [
],
"dependencies": {
"NETStandard.Library": "1.6.0",
"Microsoft.EntityFrameworkCore.Relational": "1.0.0"
},
"buildOptions": {
"define": [
"EFCore"
]
}
},
"net46": {
"dependencies": {
"EntityFramework": "6.1.3"
},
"buildOptions": {
"define": [
"EF6"
]
},
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
}
},如果我在.net框架4.6.1项目中安装我的nuget包,它也会自动安装EntityFramework 6,但我使用EntityFrameworkCore创建了我的Nuget包。
我可以更改我的Nuget包,使其始终使用targetframework netstandard而不是net46安装EntityFramework.DbContextScope吗?
编辑:到目前为止,我能做到这一点的唯一方法是手动编辑.net框架4.6.1项目的csproj文件中的hintpath。这是可行的,但远不是理想的。
<Reference Include="EntityFramework.DbContextScope, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.DbContextScope.1.0.0\lib\netstandard1.3\EntityFramework.DbContextScope.dll</HintPath>
</Reference>发布于 2019-06-15 05:26:22
此question可能会有所帮助,因为它显示了如何基于目标框架指定依赖项。
在您的示例中,它可能类似于:
<dependencies>
<group targetFramework="v4.6.1">
<dependency id="NETStandard.Library" version="1.6.0" />
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="1.0.0" />
</group>
</dependencies>如果您希望它始终安装这些版本的依赖项,而不管目标框架是什么,您也可以不指定目标框架:
<dependencies>
<group>
<dependency id="NETStandard.Library" version="1.6.0" />
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="1.0.0" />
</group>
</dependencies>https://stackoverflow.com/questions/50468720
复制相似问题