[英]Nuget Library - Copy DLL of Library to current project's output directory
So to best explain what I would like to do: 因此,最好的解释一下我想做什么:
If you install the nuget package NUnitTestAdapter to your project, when building your project, you will have a NUnit3.TestAdapter.dll in your project's output directory. 如果在项目中安装nuget软件包NUnitTestAdapter,则在构建项目时,项目的输出目录中将包含NUnit3.TestAdapter.dll。
I would like to do the same. 我也想这样做。 I have a library that I'm packaging up, but when I install it to another project and build it, my dll isn't included like NUnit's is. 我有一个要打包的库,但是当我将其安装到另一个项目并进行构建时,不像NUnit那样包含我的dll。
As for why I need to do this, I'm writing a test reporter, which produces JSONs, XMLs, HTML etc reports for all tests run. 至于为什么需要这样做,我正在编写一个测试报告器,它为所有运行的测试生成JSON,XML,HTML等报告。 I'm having this run in the AppDomain.CurrentDomain.ProcessExit event, however this is limited to around 2 seconds, so if my reports aren't generated in 2 seconds, it won't work. 我正在AppDomain.CurrentDomain.ProcessExit事件中运行此事件,但是该时间限制为2秒左右,因此,如果2秒钟内未生成我的报告,它将无法正常工作。 So instead, on processexit, it'll execute my report DLL which won't have a time restraint on it. 因此,取而代之的是,在processexit上,它将执行我的报告DLL,而该报告没有时间限制。
Thanks! 谢谢!
Nuget Library - Copy DLL of Library to current project's output directory Nuget库-将库的DLL复制到当前项目的输出目录
When you download the package NUnit3TestAdapter
and open it with NuGet Package explorer(Get it from Microsoft Store), you will find following content: 当您下载软件包NUnit3TestAdapter
并使用NuGet软件包浏览器(从Microsoft Store获取)打开它时,您会发现以下内容:
There is a NUnit3TestAdapter.props
with property CopyToOutputDirectory
in the build folder: 在构建文件夹中有一个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>
So, when we install this package to the project, this file NUnit3TestAdapter.props
will imported to the project file, then the dll files will be copied to the output folder. 因此,当我们将此软件包安装到项目中时,此文件NUnit3TestAdapter.props
将导入到项目文件中,然后将dll文件复制到输出文件夹中。
If you want that, you can also use this method. 如果需要,也可以使用此方法。
Hope this helps. 希望这可以帮助。
So with the help of Leo Liu-MSFT, I've managed this. 因此,在Leo Liu-MSFT的帮助下,我对此进行了管理。
First I had to create a props file like in Leo's answer Then I had to create a post-build event on the project, copying the props file to my target directory. 首先,我必须像Leo的答案一样创建一个props文件,然后我必须在项目上创建一个post-build事件,将props文件复制到我的目标目录中。
copy /Y "$(ProjectDir)$(TargetName).props" "$(TargetDir)$(TargetName).props"
Then I created a nuspec file, which copies the props and dll from my target directory, to a build directory in the nuget package 然后,我创建了一个nuspec文件,该文件将props和dll从我的目标目录复制到nuget包中的构建目录中
<files>
<file src="bin\Release\**\Report.props" target="build" />
<file src="bin\Release\**\Report.dll" target="build" />
</files>
And then package up the library via nuget pack ###.nuspec
然后通过nuget pack ###.nuspec
库
And then when importing the library through nuget, the props file would be automatically push my files through on a successful build. 然后,当通过nuget导入库时,props文件将在成功构建后自动推送我的文件。
I had to make sure I called the props file the same name as my project id. 我必须确保将props文件称为与项目ID相同的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.