[英]How to set up MyPackage.targets file to add all dll's into the bin/debug or bin/Release folder?
我正在學習NuGet。 我確信這不是一項不尋常的任務。 我有一些原生的dll需要添加到最終輸出中。 共有25個dll,但只有7個可以作為參考直接添加。
我目前有一個NuGet包,通過使用以下結構直接添加7個引用:
build
x64
reference1.dll
...
reference7.dll
TheOthers1.dll
...
TheOthers20.dll
MyPackage.targets
lib
net472
reference1.dll
reference2.dll
reference3.dll
reference4.dll
reference5.dll
reference6.dll
reference7.dll
我的目標文件如下所示:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<NativeLibs Include="$(MSBuildThisFileDirectory)**\*.dll" />
<None Include="@(NativeLibs)">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
我的項目輸出最終看起來像這樣:
bin/Debug
Reference1.dll
...
Reference7.dll
x64
reference1.dll
...
reference7.dll
TheOthers1.dll
...
TheOthers20.dll
當我運行應用程序時,我得到:
System.IO.FileNotFoundException:'無法加載文件或程序集'reference1.dll'或其依賴項之一。 指定的模塊無法找到。'
如果我將x64文件夾中的dll復制到bin / Debug文件夾中,應用程序就會運行。
如何構建.targets文件以將build / x64中的所有dll復制到bin / Debug或bin / release中?
對於本機DLL,始終始終如一地設置<OutDir>
屬性。 這決定了編譯后的二進制文件的位置。 這將看起來像:
<OutDir>bla bla bla\bin\$(Configuration)\</OutDir>
注意它也必須以反斜杠結尾。
對於托管DLL,始終始終如一地設置<OutputPath>
屬性。 這決定了編譯的托管程序集的位置。 這將看起來像:
<OutputPath>bla bla bla\bin\$(Configuration)\</OutputPath>
注意他們都去了同一個地方?
我有類似的問題。 我通過使用“復制”功能解決了這個問題。 請看下面的示例:
<Target Name="CopyREsources" AfterTargets="Build">
<Copy
SourceFiles="$(MSBuildThisFileDirectory)PDFtoPrinter.exe"
DestinationFiles="$(MSBuildProjectDirectory)\bin\$(Configuration)\PDFtoPrinter.exe"
Condition="!Exists('$(MSBuildProjectDirectory)\bin\$(Configuration)\PDFtoPrinter.exe')" />
</Target>
完整代碼可在此處獲得 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.