Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy to $(OutDir) does not copy to benchmarkdotnet output folder #946

Open
jorisdebock opened this issue Nov 5, 2018 · 9 comments
Open

Copy to $(OutDir) does not copy to benchmarkdotnet output folder #946

jorisdebock opened this issue Nov 5, 2018 · 9 comments
Assignees

Comments

@jorisdebock
Copy link

@jorisdebock jorisdebock commented Nov 5, 2018

I have the following Copy action defined in my .csproj

<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
   <Copy SourceFiles="@(files)" DestinationFolder="$(OutDir)" />
</Target>

When I try to run BenchmarkDotNet it does not copy the files to the \bin\release<Guid>... folder but just the default output folder.

What is the correct configuration to make this work?

@ydsood
Copy link

@ydsood ydsood commented Jul 17, 2019

Is there any solution for this issue so far?

@morgan-kn
Copy link
Collaborator

@morgan-kn morgan-kn commented Jul 22, 2019

In this case we can't just add Copy to SettingsWeWantToCopy because the Copy command contains parameters (i.e. SourceFiles, DestinationFolder, etc) which may refer to some properties in csproj, and we'll be forced to process them all.

I suggest to copy the content of user's bin folder to benchmark's bin folder assuming that user puts in there only files that he or she needs.

@adamsitnik What do you think?

@WojciechNagorski
Copy link
Collaborator

@WojciechNagorski WojciechNagorski commented Sep 25, 2019

Instead of post-build events you should use None or Compile items in your csproj, like below:

<ItemGroup>
  <None Include="$(MSBuildThisFileDirectory)..\x64\$(Configuration)\NativeDll.dll">
    <Link>NativeDll.dll</Link>
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <Visible>True</Visible>
  </None>
</ItemGroup>

You can also copy the entire directory, using this method:

  <ItemGroup>
    <None Include="C:\Resources\**\*.*">
      <Link>%(Directory)\%(Filename)%(Extension)</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Visible>True</Visible>
    </None>
  </ItemGroup>

@WojciechNagorski
Copy link
Collaborator

@WojciechNagorski WojciechNagorski commented Sep 30, 2019

I just blogged about this topic: https://wojciechnagorski.com/2019/09/using-native-dll-and-resource-files-in-benchmarkdotnet-projects/

I think BenchmarkDotNet should display a warning when AfterBuild or BeforBuild contains <Copy SourceFiles ...> in the csproj file.

@adamsitnik What do you think?

@adamsitnik
Copy link
Member

@adamsitnik adamsitnik commented Sep 30, 2019

I wonder if we could come up with a more generic solution implemented on the BDN side that would be transparent to the end-user. For example: by extending the auto-generated .csproj file with some MSBuild magic that would copy every native library from the benchmark project output folder to the auto-generated project output folder.

@eerhardt would copying all the files help with dotnet/performance#894 ? Do you have any suggestions for a more generic solution?

@eerhardt
Copy link
Member

@eerhardt eerhardt commented Sep 30, 2019

I agree with @wojtpl2 that using CopyToOutputDirectory on a None/Content item is probably best in this situation. It just works because we have a Project-to-Project Reference to the end-user's .csproj, and all the output items will get copied to the auto-generated .csproj.

As for helping with dotnet/performance#894, the native assemblies in that scenario should be getting copied to the output folder by default, because they come through a NuGet package. With the 3.0 .NET SDK, all the assets from NuGet packages should be copied to the output directory by default.

@bonesoul
Copy link

@bonesoul bonesoul commented May 4, 2020

I've tried

<ItemGroup>
   <None Include="$(TargetDir)config\**\*.*">
     <Link>%(Directory)\%(Filename)%(Extension)</Link>
     <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     <Visible>False</Visible>
   </None>
 </ItemGroup>

but still can't get my config files copied to benchmarkdotnet generated guid folder.

any ideas?

@codingdave
Copy link

@codingdave codingdave commented Jan 14, 2021

@bonesoul try Always instead of PreserveNewest. I'm also struggling with this.

Actually my background is that I want to benchmark a .net library with uses a huge C++ project under the hood that is made accessible with a C++/CLI wrapper. Because I have several projects that use C++ and .Net and generated files I have written clean msbuild target files that do the copying job for me. Unfortunately this clean approach does not work for BenchmarkDotNet and I will spend some time today to "invent" the deployment logic to work. A bit unfortunate because it takes some time to understand the reason for the benchmarks failing and some time more to make it work.

@codingdave
Copy link

@codingdave codingdave commented Jan 19, 2021

@bonesoul I finally succeeded with

<None Include="$(OutDir)\**\*">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  <Link>%(RecursiveDir)\%(Filename)%(Extension)</Link>
  <Visible>False</Visible>
</None>

Please note: This method requires that all your resources you want to carry along need to exist at $(OutDir) when you start your compilation. If later build steps add certain files it is likely BenchmarkDotNet will not find them at runtime because they werent there when the compilation was expanding the variable $(OutDir)\**\*.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants