2

Using firefox geckodriver in ASP.NET Core, I noticed that geckodriver.exe is copied to bin\Debug\netcoreapp2.1, which work fine during debugging. But after publishing, it's not present in bin\Debug\netcoreapp2.1\publish.

So I'm trying to copy it using csproj file with this ItemGroup

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

The file is found, cause when I change the path to $(TargetDir)\geckodriver2.exe I get an error that geckodriver2.exe doesn't exist. But it doesn't copy geckodriver.exe to publish directory.

Lion
  • 16,606
  • 23
  • 86
  • 148

1 Answers1

1

After manually deleting bin\Debug\netcoreapp2.1\publish and running dotnet publish I noticed that geckodriver was copied to bin\Debug\netcoreapp2.1\publish\bin\Debug\netcoreapp2.1. So it seems that my file was not copied for some kind of caching issue.

Since the destination is still wrong, I found this blogpost about copying files which gave me the right hint:

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

Now the executable is correctly copied to bin\Debug\netcoreapp2.1\publish.

Lion
  • 16,606
  • 23
  • 86
  • 148