将来自Nuget程序包的非托管DLL包含到Web Deploy程序包中 [英] Include Unmanaged DLL from Nuget package to web Deploy package

查看:178
本文介绍了将来自Nuget程序包的非托管DLL包含到Web Deploy程序包中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Nuget程序包,其中包含非托管DLL,并且目标是将此DLL复制到输出文件夹:

I have Nuget package which contains unmanaged DLL and target to copy this DLL to output folder:

<?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Target Name="AfterBuild" DependsOnTargets="CopyFilesToOutputDirectory">
          <ItemGroup>
              <MyPackageSourceFile Include="$(SolutionDir)\packages\somepackage\unmanaged\*.dll" />
          </ItemGroup>
          <Copy SourceFiles="@(MyPackageSourceFile)" DestinationFolder="$(OutputPath)" />
      </Target>
</Project>

这在我构建项目(使用Visual Studio)时非常有用

This perfectly works when I am building project(Using Visual Studio)

但是,如果我要创建发布包(到文件系统或再次使用VS进行Web部署),则不包含这些dll.

However if I want to create publish package(To File System, or Web Deploy again using VS) those dlls are not included.

有什么建议吗?

推荐答案

将非托管DLL从Nuget程序包添加到Web部署程序包

Include Unmanaged DLL from Nuget package to web Deploy package

您可以在NuGet包中的目标AfterBuild之后添加另一个目标,以动态地将那些非托管DLL文件包括到您的项目文件中,或者将目标简单地添加到项目文件中.

You can add another target after target AfterBuild in your NuGet package to dynamically include those unmanaged DLL files to your project file or simple add the target to the project file.

要完成此操作,请在您的NuGet包中添加目标顺序为AfterTargets="AfterBuild"的目标:

To accomplish this, add a target with target order AfterTargets="AfterBuild" in your NuGet package:

  <Target Name="AddUnmanagedDll" AfterTargets="AfterBuild">  
    <ItemGroup>
      <Content Include="$(OutputPath)\*.dll" />
    </ItemGroup>
  </Target>

但是此目标将添加所有dll文件,包括托管的dll文件.要解决此问题,我们需要更改先前的目标AfterBuild以添加另一个复制任务,以将那些不受管理的dll文件复制到单独的文件夹中:

But this target will add all dll files, including managed dll files. To resolve this issue, we need to change previous target AfterBuild to add another copy task to copy those unmanaged dll files to a separate folder:

  <Target Name="AfterBuild" DependsOnTargets="CopyFilesToOutputDirectory">
    <ItemGroup>
      <MyPackageSourceFile Include="$(SolutionDir)packages\somepackage\unmanaged\*.dll" />
    </ItemGroup>
    <Copy SourceFiles="@(MyPackageSourceFile)" DestinationFolder="$(OutputPath)" />
    <Copy SourceFiles="@(MyPackageSourceFile)" DestinationFolder="$(ProjectDir)UnmanagedDll" />
  </Target>

添加另一个复制任务<Copy SourceFiles="@(MyPackageSourceFile)" DestinationFolder="$(ProjectDir)UnmanagedDll" />之后,将非托管dll文件复制到单独的文件夹$(ProjectDir)UnmanagedDll.

After add the another copy task <Copy SourceFiles="@(MyPackageSourceFile)" DestinationFolder="$(ProjectDir)UnmanagedDll" /> to copy the unmanaged dll files to the separate folder $(ProjectDir)UnmanagedDll.

然后我们可以将目标AddUnmanagedDll中的ItemGroup <Content Include="$(OutputPath)\*.dll" />更改为<Content Include="UnmanagedDll\*.dll" />

Then we could change the ItemGroup <Content Include="$(OutputPath)\*.dll" /> in the target AddUnmanagedDll to <Content Include="UnmanagedDll\*.dll" />

因此,NuGet包中的目标应为:

So the targets in the NuGet package should be:

  <Target Name="AfterBuild" DependsOnTargets="CopyFilesToOutputDirectory">
    <ItemGroup>
      <MyPackageSourceFile Include="$(SolutionDir)packages\app.1.0.0\unmanaged\*.dll" />
    </ItemGroup>
    <Copy SourceFiles="@(MyPackageSourceFile)" DestinationFolder="$(OutputPath)" />
    <Copy SourceFiles="@(MyPackageSourceFile)" DestinationFolder="$(ProjectDir)UnmanagedDll" />
  </Target>

  <Target Name="AddUnmanagedDll" AfterTargets="AfterBuild">  
    <ItemGroup>
      <Content Include="UnmanagedDll\*.dll" />
    </ItemGroup>
  </Target>

发布项目后,那些不受管理的项目将包含在Web Deploy程序包中:

After publish the project, those unmanaged are included in the web Deploy package:

这篇关于将来自Nuget程序包的非托管DLL包含到Web Deploy程序包中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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