简体   繁体   English

将来自Nuget包的非托管DLL包括到Web Deploy包中

[英]Include Unmanaged DLL from Nuget package to web Deploy package

I have Nuget package which contains unmanaged DLL and target to copy this DLL to output folder: 我有Nuget程序包,其中包含非托管DLL,并且目标是将此DLL复制到输出文件夹:

<?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>

This perfectly works when I am building project(Using Visual Studio) 当我构建项目时(使用Visual Studio),这完全可以正常工作

However if I want to create publish package(To File System, or Web Deploy again using VS) those dlls are not included. 但是,如果我要创建发布包(到文件系统或再次使用VS进行Web部署),则不包含这些dll。

Any suggestions? 有什么建议么?

Include Unmanaged DLL from Nuget package to web Deploy package 将来自Nuget包的非托管DLL包括到Web Deploy包中

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包中的目标AfterBuild之后添加另一个目标,以将那些非托管DLL文件动态包括到您的项目文件中,或将目标简单地添加到项目文件中。

To accomplish this, add a target with target order AfterTargets="AfterBuild" in your NuGet package: 为此,请在您的NuGet包中添加目标顺序为AfterTargets="AfterBuild"目标:

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

But this target will add all dll files, including managed dll files. 但是此目标将添加所有dll文件,包括托管dll文件。 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 : 要解决此问题,我们需要更改先前的目标AfterBuild以添加另一个复制任务,以将那些非托管dll文件复制到单独的文件夹中

  <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>

After add the another copy task <Copy SourceFiles="@(MyPackageSourceFile)" DestinationFolder="$(ProjectDir)UnmanagedDll" /> to copy the unmanaged dll files to the separate folder $(ProjectDir)UnmanagedDll . 添加另一个复制任务后<Copy SourceFiles="@(MyPackageSourceFile)" DestinationFolder="$(ProjectDir)UnmanagedDll" />托管dll文件复制到单独的文件夹$(ProjectDir)UnmanagedDll

Then we could change the ItemGroup <Content Include="$(OutputPath)\\*.dll" /> in the target AddUnmanagedDll to <Content Include="UnmanagedDll\\*.dll" /> 然后,我们可以将目标AddUnmanagedDll的ItemGroup <Content Include="$(OutputPath)\\*.dll" /> AddUnmanagedDll<Content Include="UnmanagedDll\\*.dll" />

So the targets in the NuGet package should be: 因此,NuGet包中的目标应为:

  <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>

After publish the project, those unmanaged are included in the web Deploy package: 发布项目后,那些不受管理的项目将包含在Web Deploy软件包中:

在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM