简体   繁体   English

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

[英]Embedded library in multi targeting .NET project

I have a .NET project that has 2 target frameworks: netstandard1.6 and net40.我有一个 .NET 项目,它有 2 个目标框架:netstandard1.6 和 net40。 I am trying to embedded a libraries (ICU4N and J2N) that has target on netstandard1.3 and net40.我正在尝试嵌入一个以 netstandard1.3 和 net40 为目标的库(ICU4N 和 J2N)。

I created a ...\lib\ folder where I put.dll libraries for the corresponding targets.我创建了一个...\lib\文件夹,我将.dll 库用于相应的目标。

My.csprog file looks like this My.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>

When I run the program,当我运行程序时,

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

error is issued, this error appears due to the fact that files ...\bin\Debug\net40\ICU4N.dll and ...\bin\Debug\netstandard1.6\ICU4N.dll are the same, but should be different.发出错误,出现此错误是因为文件...\bin\Debug\net40\ICU4N.dll...\bin\Debug\netstandard1.6\ICU4N.dll相同,但应该不同.

The question is how to configure the project and.csproj file so that during build the version of the netstandard1.3 library falls into the folder ...\bin\Debug\netstandard1.6\ , and net40 version of the library into folder ...\bin\Debug\net40\ , because now the net40 version of the library falls into folder ...\bin\Debug\netstandard1.6\ and ...\bin\Debug\net40\ .问题是如何配置项目和 .csproj 文件,以便在构建期间 netstandard1.3 库的版本落入文件夹...\bin\Debug\netstandard1.6\ ,而 net40 版本的库落入文件夹...\bin\Debug\net40\ ,因为现在 net40 版本的库属于文件夹...\bin\Debug\netstandard1.6\...\bin\Debug\net40\

Thank you in advance.先感谢您。

The problem is in HintPath , the first found library was embedded.问题出在HintPath中,第一个找到的库是嵌入的。

Decision: Add the following code for netstanard1.6 target block.决定:为 netstanard1.6 目标块添加以下代码。

    <None Remove="lib\ICU4N\net40\ICU4N.dll" />
    <None Remove="lib\J2N\net40\J2N.dll" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows 8.1可移植类库项目针对多平台的情况下,NETFX_CORE等效于什么? - What is the equivalent of NETFX_CORE in the case of windows 8.1 portable class library project targeting multi-platform? .NETStandard 多目标库包在 Netstandard 2.0 项目上给我 CS0234 错误 - .NETStandard multi-targeting library packages gives me CS0234 error on Netstandard 2.0 project Nuget库的多运行时目标 - Multi-Runtime Targeting of Library for Nuget 如何针对net45的类库(包)项目运行xunit测试? - How do I run xunit tests for a Class Library (Package) project targeting net45? 在面向.NET 4的项目中引用.NET 2程序集 - Referencing a .NET 2 assembly in a project targeting .NET 4 如何构建一个面向.NET Core的类库? - How to scaffold a Class Library targeting .NET Core? 在 Xamarin 项目中面向 .NET Framework 4.6.1 - Targeting .NET Framework 4.6.1 in Xamarin project 多目标 .net 核心 2.2 与 .net 4.6.1 - Multi-targeting .net core 2.2 with .net 4.6.1 尝试将针对.NET 3.5的项目添加到针对.NET 4.0的现有项目 - Trying to add a project targeting .NET 3.5 to an existing project targeting .NET 4.0 创建库.tar Framework 4.5和.Net Standard - Create library targeting .Net Framework 4.5 and .Net Standard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM