[英]Include Unmanaged DLL from Nuget package to web Deploy package
我有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>
当我构建项目时(使用Visual Studio),这完全可以正常工作
但是,如果我要创建发布包(到文件系统或再次使用VS进行Web部署),则不包含这些dll。
有什么建议么?
将来自Nuget包的非托管DLL包括到Web Deploy包中
您可以在NuGet包中的目标AfterBuild
之后添加另一个目标,以将那些非托管DLL文件动态包括到您的项目文件中,或将目标简单地添加到项目文件中。
为此,请在您的NuGet包中添加目标顺序为AfterTargets="AfterBuild"
目标:
<Target Name="AddUnmanagedDll" AfterTargets="AfterBuild">
<ItemGroup>
<Content Include="$(OutputPath)\*.dll" />
</ItemGroup>
</Target>
但是此目标将添加所有dll文件,包括托管dll文件。 要解决此问题,我们需要更改先前的目标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>
添加另一个复制任务后<Copy SourceFiles="@(MyPackageSourceFile)" DestinationFolder="$(ProjectDir)UnmanagedDll" />
托管dll文件复制到单独的文件夹$(ProjectDir)UnmanagedDll
。
然后,我们可以将目标AddUnmanagedDll
的ItemGroup <Content Include="$(OutputPath)\\*.dll" />
AddUnmanagedDll
为<Content Include="UnmanagedDll\\*.dll" />
因此,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>
发布项目后,那些不受管理的项目将包含在Web Deploy软件包中:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.