BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

Change the way of generating new project file

Open adamsitnik opened this issue 4 years ago • 10 comments

As of today, we generate the .csproj file by filling this text template.

The main disadvantage of this approach is that if there are any custom MSBuild settings in the project with a benchmark that we are not aware of, we sometimes fail to build the project and hence fail to run the benchmarks.

We used to follow a similar approach for generating the app.config files, but at some point in time we changed the approach to "rewrite everything from the source file unless it's on our list of settings". The code can be found here

I propose that we switch to a similar approach with the .csproj file:

  • copy the source project file
  • update all relative paths
  • replace the settings we know (TFM, optimizations enabled, project name etc)
  • add a reference to the source project

This should fix:

  • Forward msbuild properties to project reference #1377
  • This type has been forwarded to assembly #1392
  • Not able to run a project referencing to private nuget package #1358
  • Can I run a CMD command during the toolchain lifecycle? #1345
  • Enable including references in autogenerated csproject #1197

and a few more issues

adamsitnik avatar Mar 24 '20 10:03 adamsitnik

@WojciechNagorski if you are still looking for some task then most probably this one would have the biggest impact (it's going to solve at least 10+ bugs)

adamsitnik avatar Mar 24 '20 11:03 adamsitnik

@adamsitnik Yes, I would like to solve this task. I will find time next week.

WojciechNagorski avatar Mar 24 '20 13:03 WojciechNagorski

Yes, I would like to solve this task. I will find time next week.

Awesome! I've assigned you to the task.

adamsitnik avatar Mar 24 '20 13:03 adamsitnik

Update: I've thought for 2 weeks and I think that I invented the final solution for all cases.

WojciechNagorski avatar Apr 15 '20 09:04 WojciechNagorski

@WojciechNagorski awesome :D

adamsitnik avatar Apr 15 '20 09:04 adamsitnik

Hi, is there any progress on the implementation? I am only asking because it sounded like the problem was basically solved. :)

We also have a custom build configuration to do out-of-tree builds, and currently use the workaround of putting a stripped-down Directory.Build.props (which does not change any output paths) into the build output dir.

ilohmar avatar Mar 17 '21 11:03 ilohmar

@ilohmar @adamsitnik After I wanted to fix this problem I changed the project at work, then I changed work at all. So I didn't have time for this task. Currently, I have only an idea but I don't have time for it.

WojciechNagorski avatar Mar 17 '21 13:03 WojciechNagorski

@WojciechNagorski If you don't have time to work on this, could you leave your thoughts on what the solution should be so someone can work on it?

timcassell avatar Jun 30 '23 23:06 timcassell

@timcassell I had some ideas and wanted to test them one by one. Two ideas are particularly promising. But I don't want to describe them because I'd have to bring back the details and that's also work and time. I would love to do this and more, even full-time, but this was only a free contribution and fun.

WojciechNagorski avatar Jul 05 '23 12:07 WojciechNagorski

update all relative paths

I'm unsure of how to reliably do this. <Reference Include=""> could be a path, or an assembly name, and it's undocumented how to determine what it is. At least I couldn't find the documentation. https://learn.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items?view=vs-2022 doesn't even mention the Include attribute.

[Edit] Also if the paths/assemblies include variables in them, it would be next to impossible for us to determine that without having our own mock-msbuild to resolve them.

The easiest thing to do would be to produce the generated csproj in the same directory as the original xproj. It's not ideal since it would clutter the original project directory and is separated from the generated code, but it would be able resolve all paths correctly without us having to try to guess.

Any thoughts on that @AndreyAkinshin @adamsitnik?

timcassell avatar Jul 06 '23 17:07 timcassell