c# - 如何从 .NetStandard 类库中引用 net40 框架程序集?

标签 c# .net csproj .net-standard project.json

在 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/

相关文章:

.net - 使用 Redis CLI 连接到远程 Azure Redis 缓存

c# - c# 项目中没有 .sln 文件

visual-studio - Visual Studio 链接文件目录结构

c# - 用于DirectShow的Matroska Muxer过滤器

c# - 在树中转换表

C# 类声明 "from metadata"

c# - ParseExact 不解析带有日期的字符串,带有序数但没有年份的日期

c# - Unity - 在没有 resolve() 的情况下解析

visual-studio - 在 Visual Studio (2008) 中,有没有办法在另一个自定义文件上创建自定义依赖文件?

c# - "111 -> c:\my source\file1.cpp (no code)"的正则表达式 (C#)