[英]Do I have to copy the DLLs from the Nuget Package to the output directory everytime I use the Nuget Package in NetStandard Library Project
[英]Nuget Library - Copy DLL of Library to current project's output directory
因此,最好的解釋一下我想做什么:
如果在項目中安裝nuget軟件包NUnitTestAdapter,則在構建項目時,項目的輸出目錄中將包含NUnit3.TestAdapter.dll。
我也想這樣做。 我有一個要打包的庫,但是當我將其安裝到另一個項目並進行構建時,不像NUnit那樣包含我的dll。
至於為什么需要這樣做,我正在編寫一個測試報告器,它為所有運行的測試生成JSON,XML,HTML等報告。 我正在AppDomain.CurrentDomain.ProcessExit事件中運行此事件,但是該時間限制為2秒左右,因此,如果2秒鍾內未生成我的報告,它將無法正常工作。 因此,取而代之的是,在processexit上,它將執行我的報告DLL,而該報告沒有時間限制。
謝謝!
Nuget庫-將庫的DLL復制到當前項目的輸出目錄
當您下載軟件包NUnit3TestAdapter
並使用NuGet軟件包瀏覽器(從Microsoft Store獲取)打開它時,您會發現以下內容:
在構建文件夾中有一個NUnit3TestAdapter.props
屬性為CopyToOutputDirectory
:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)NUnit3.TestAdapter.dll">
<Link>NUnit3.TestAdapter.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</Content>
<Content Include="$(MSBuildThisFileDirectory)NUnit3.TestAdapter.pdb" Condition="Exists('$(MSBuildThisFileDirectory)NUnit3.TestAdapter.pdb')">
<Link>NUnit3.TestAdapter.pdb</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</Content>
<Content Include="$(MSBuildThisFileDirectory)nunit.engine.dll">
<Link>nunit.engine.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</Content>
<Content Include="$(MSBuildThisFileDirectory)nunit.engine.api.dll">
<Link>nunit.engine.api.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</Content>
</ItemGroup>
</Project>
因此,當我們將此軟件包安裝到項目中時,此文件NUnit3TestAdapter.props
將導入到項目文件中,然后將dll文件復制到輸出文件夾中。
如果需要,也可以使用此方法。
希望這可以幫助。
因此,在Leo Liu-MSFT的幫助下,我對此進行了管理。
首先,我必須像Leo的答案一樣創建一個props文件,然后我必須在項目上創建一個post-build事件,將props文件復制到我的目標目錄中。
copy /Y "$(ProjectDir)$(TargetName).props" "$(TargetDir)$(TargetName).props"
然后,我創建了一個nuspec文件,該文件將props和dll從我的目標目錄復制到nuget包中的構建目錄中
<files>
<file src="bin\Release\**\Report.props" target="build" />
<file src="bin\Release\**\Report.dll" target="build" />
</files>
然后通過nuget pack ###.nuspec
庫
然后,當通過nuget導入庫時,props文件將在成功構建后自動推送我的文件。
我必須確保將props文件稱為與項目ID相同的名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.