将文件(geckodriver.exe)复制到发布文件夹 ASP.NET 发布核心MVC 2.1项目



在 ASP.NET Core中使用Firefox geckodriver,我注意到geckodriver.exe被复制到binDebugnetcoreapp2.1,这在调试过程中工作正常。但是发布后,它就没有出现在binDebugnetcoreapp2.1publish中。

所以我正在尝试使用此ItemGroup使用 csproj 文件复制它

<ItemGroup>
<Content Include="$(TargetDir)geckodriver.exe" CopyToPublishDirectory="Always" />
</ItemGroup>

找到该文件,因为当我将路径更改为$(TargetDir)geckodriver2.exe时,我收到geckodriver2.exe不存在的错误。但它不会geckodriver.exe复制到publish目录中。

手动删除binDebugnetcoreapp2.1publish并运行dotnet publish后,我注意到geckodriver被复制到binDebugnetcoreapp2.1publishbinDebugnetcoreapp2.1。因此,似乎我的文件不是由于某种缓存问题而复制的。

由于目的地仍然错误,我找到了这篇关于复制文件的博客文章,它给了我正确的提示:

<Content Include="$(TargetDir)geckodriver.exe" CopyToPublishDirectory="Always">
<Link>geckodriver.exe</Link>
</Content>

现在可执行文件已正确复制到binDebugnetcoreapp2.1publish.

最新更新