[英]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.