![](/img/trans.png)
[英]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.