在哪里放置非托管库的 dll? [英] Where to place dlls for unmanaged libraries?

查看:22
本文介绍了在哪里放置非托管库的 dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为依赖 ghostscript 的库创建 Nuget 包,因此引用 gsdll32.dll - 一个非托管库.我不能只包含一个标准的 dll 引用.我在哪里把它放在 nuget 目录结构中?

I am trying to create a Nuget package for a library that depends on ghostscript and therefore references gsdll32.dll - an unmanaged library. I can't just included that a standard dll reference. Where do I put this in the nuget directory structure?

推荐答案

build 文件夹添加到包中,例如,如果包的 id 为 MyPackage,将名为 MyPackage.targets 的 MSBuild 目标文件添加到此文件夹..targets 文件与 .nuspec 文件同名很重要.在 .nuspec 文件中,您必须有这样的部分:

Add a build folder to the package and, if the package for example has the id MyPackage, add a MSBuild target file called MyPackage.targets to this folder. It is important that the .targets file has the same name as the .nuspec file. In the .nuspec file you must have a section like this:

<files>
    <file src="lib*.*" target="lib" />
    <file src="buildMyPackage.targets" target="build" />
</files>

这将在项目文件中添加一个指向 .targets 文件的 MSBuild 元素.

This will add an MSBuild element in the project file pointing to the .targets file.

此外,要仅注册托管 dll,请添加如下部分:

Furthermore, to only register the managed dlls, add a section like this:

<references>
    <reference file="MyManaged.dll" />
</references>

.targets 文件应如下所示:

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
  <Target Name="CopyMyPackageFiles" AfterTargets="AfterBuild"> 
    <ItemGroup> 
      <MyPackageFiles Include="$(MSBuildThisFileDirectory)..lib*.*"/> 
    </ItemGroup> 
    <Copy SourceFiles="@(MyPackageFiles)" DestinationFolder="$(OutputPath)" > 
    </Copy> 
  </Target> 
</Project>

现在,所有文件 - 包括非托管文件 - 将在构建后复制到项目输出文件夹(例如 indebug).

Now, all files - including unmanaged files - will be copied to the project output folder (e.g. indebug) after the build.

这篇关于在哪里放置非托管库的 dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆