在 project.json 项目系统下,我能够为每个框架指定框架程序集依赖项。 dotnet docs (现已过时)显示以下示例。
{
"frameworks":{
"net20":{
"frameworkAssemblies":{
"System.Net":""
}
},
"net35":{
"frameworkAssemblies":{
"System.Net":""
}
},
"net40":{
"frameworkAssemblies":{
"System.Net":""
}
},
"net45":{
"frameworkAssemblies":{
"System.Net.Http":"",
"System.Threading.Tasks":""
}
},
".NETPortable,Version=v4.5,Profile=Profile259": {
"buildOptions": {
"define": [ "PORTABLE" ]
},
"frameworkAssemblies":{
"mscorlib":"",
"System":"",
"System.Core":"",
"System.Net.Http":""
}
},
"netstandard16":{
"dependencies":{
"NETStandard.Library":"1.6.0",
"System.Net.Http":"4.0.1",
"System.Threading.Tasks":"4.0.11"
}
},
}
}
如何在 csproj 下为更新的 dotnet sdk v1.1.1 执行此操作?我想为 net40 引用 System.Configuration,但不为 netstandard 1.6 引用。
最佳答案
谢谢 Pankaj - 我采纳了您建议的修改版本。关键在于使用 Reference 元素。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.6;net40</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.6'">
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.0" />
<PackageReference Include="Common.Logging" Version="3.4.0-Beta2" />
<PackageReference Include="NLog" Version="5.0.0-beta06" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
<PackageReference Include="Common.Logging" Version="3.3.0" />
<PackageReference Include="NLog" Version="4.1.1" />
<PackageReference Include="Common.Logging.NLog40" Version="3.3.0" />
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<Folder Include="Console\" />
</ItemGroup>
</Project>
关于c# - 如何从 .NetStandard 类库中引用 net40 框架程序集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42775761/