Include Unmanaged DLL from Nuget package to web Deploy package

前端 未结 1 977
深忆病人
深忆病人 2021-01-27 20:30

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


    

        
相关标签:
1条回答
  • 2021-01-27 20:50

    Include Unmanaged DLL from Nuget package to web Deploy package

    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.

    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>
    

    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>
    

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

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

    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>
    

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

    0 讨论(0)
提交回复
热议问题