我制作了一个依赖于 CefSharp 的库,它需要为特定平台构建库。所以没有 AnyCPU 支持。
现在我想把它打包成一个 NuGet。据我了解,您必须将这些文件放入 build 文件夹并拥有一个.targets
选择正确 dll 来引用的文件。所以我最终得到了一个如下所示的 NuGet 包:
lib
monodroid
MyLib.dll
xamarin.ios10
MyLib.dll
net45
MyLib.dll (x86)
build
net45
x86
MyLib.dll (x86)
x64
MyLib.dll (x64)
MyLib.targets
我将以下内容放入.targets
文件中:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PlatformCheck" BeforeTargets="InjectReference"
Condition="(('$(Platform)' != 'x86') AND ('$(Platform)' != 'x64'))">
<Error Text="$(MSBuildThisFileName) does not work correctly on '$(Platform)' platform. You need to specify platform (x86 or x64)." />
</Target>
<Target Name="InjectReference" BeforeTargets="ResolveAssemblyReferences">
<ItemGroup Condition="'$(Platform)' == 'x86' or '$(Platform)' == 'x64'">
<Reference Include="MyLib">
<HintPath>$(MSBuildThisFileDirectory)$(Platform)\MyLib.dll</HintPath>
</Reference>
</ItemGroup>
</Target>
</Project>
到目前为止,一切都很好。现在来解决问题。将此 NuGet 添加到新的 WPF 项目时,我看到对库的引用出现在.csproj
文件中,例如:
<Reference Include="MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d64412599724c860, processorArchitecture=x86">
<HintPath>..\packages\MyLib.0.0.1\lib\net45\MyLib.dll</HintPath>
<Private>True</Private>
</Reference>
尽管我没有看到有关该.targets
文件的任何内容。这仍然是使用 NuGet 3 的方法吗?我做错什么了吗?目前,由于对 x86 库的引用,这在运行 x64 时会在运行时失败。