[英]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.