多目标.NET项目中的嵌入式库

问题描述 投票:0回答:1

我有一个.NET项目,该项目具有2个目标框架:netstandard1.6和net40。我正在尝试嵌入一个以netstandard1.3和net40为目标的库(ICU4N和J2N)。

我创建了一个...\lib\文件夹,在其中放置了用于相应目标的.dll库。

我的.csprog文件看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
  <PropertyGroup Label="Configuration">
    <SignAssembly>True</SignAssembly>
    <DelaySign>False</DelaySign>
    <DocumentationFile>$(TargetDir)bin\$(Configuration)\$(TargetFramework)\someName.xml</DocumentationFile>
  </PropertyGroup>
  <PropertyGroup>
    <TargetFrameworks>netstandard1.6;net40</TargetFrameworks>
  </PropertyGroup>
  <PropertyGroup>
    <OutputType>library</OutputType>
  </PropertyGroup>

  ...

  <PropertyGroup>
    <NoWarn>1701;1702;1591;1570;1572;1573;1574;1580;1584;1658</NoWarn>
  </PropertyGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
    <Reference Include="System" />
  </ItemGroup>

  ...

  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
    <PackageReference Include="Microsoft.NETCore.Portable.Compatibility" Version="1.0.1" />

    <Reference Include="ICU4N, Version=60.0.0.0, Culture=neutral, PublicKeyToken=efb17c8e4f0e291b">
      <HintPath>lib\ICU4N\netstandard1.3\ICU4N.dll</HintPath>
    </Reference>
    <Reference Include="J2N, Version=2.0.0.0, Culture=neutral, PublicKeyToken=f39447d697a969af">
      <HintPath>lib\J2N\netstandard1.3\J2N.dll</HintPath>
    </Reference>
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
    <Reference Include="ICU4N, Version=60.0.0.0, Culture=neutral, PublicKeyToken=efb17c8e4f0e291b">
      <HintPath>lib\ICU4N\net40\ICU4N.dll</HintPath>
    </Reference>
    <Reference Include="J2N, Version=2.0.0.0, Culture=neutral, PublicKeyToken=f39447d697a969af">
      <HintPath>lib\J2N\net40\J2N.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>

当我运行程序时,

System.IO.FileNotFoundException : Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

发出错误,由于文件...\bin\Debug\net40\ICU4N.dll...\bin\Debug\netstandard1.6\ICU4N.dll相同,但应该不同而出现此错误。

问题是如何配置项目和.csproj文件,以便在构建期间将netstandard1.3库的版本放入文件夹...\bin\Debug\netstandard1.6\,将库的net40版本放入文件夹...\bin\Debug\net40\,因为现在是net40库的版本位于文件夹...\bin\Debug\netstandard1.6\...\bin\Debug\net40\中。

先谢谢您。

c# .net embedded-resource csproj
1个回答
0
投票

问题出在HintPath中,第一个找到的库已嵌入。

决定:为netstanard1.6目标块添加以下代码。

    <None Remove="lib\ICU4N\net40\ICU4N.dll" />
    <None Remove="lib\J2N\net40\J2N.dll" />
© www.soinside.com 2019 - 2024. All rights reserved.