0

I am building multiple target frameworks in a single .net 6 project: net461 and net6.0. The two target frameworks build concurrently in Visual Studio as expected. Oddly, my net6.0 post-build event depend on the net461 post-build event. I have not found a way for the msbuild targets for one target framework to be dependent on those of another target framework. So I can't ensure the post-build events execute in the proper sequence.

After looking at mechanisms in msbuild to affect build target order and dependencies, I'm not finding an answer. I'm almost about to mess around with generating and waiting for lock files in my builds but was hoping not to need to. Any ideas?

Why my net6.0 build depends on my net461 build: I am using COM in .net 6 to expose functionality to a legacy COM client. This works but there is currently no tool to generate a TLB file for .net core that I need. (regasm.exe works for .net framework but not .net core.) One workaround is to build the same COM classes/interfaces, possibly stubbed, in .net framework to then generate the TLB file. This is what I do, and then use it in my net6.0 post-build event.

Buzz
  • 512
  • 1
  • 4
  • 11
  • Did some simple tests and checked the detailed output log, looks like MSBuild starts to build with the order of which `targetframework` written first. For example, if write like this `net461;net6.0`, then MSBuild use/configure net461 first and then use/configure net6.0. So for this `net6.0; net461`, MSBuild use net6.0 first. – Tianyu Aug 12 '21 at 08:38
  • Of course it doesn’t mean MSBuild prepare/use/configure all the first target framework and then change to configure the second target framework, it works more like this => prepare for .net6.0 => prepare for .net 461 => do something for net6.0 => do something for net461… – Tianyu Aug 12 '21 at 08:39
  • But the curious thing I find is that no matter how to change, if I define two Targets for post build event, and set to start under different conditions, for example `Condition="'$(TargetFramework)' == 'net472'"` and `Condition="'$(TargetFramework)' == 'netcoreapp3.1'"`, build and check the output log, the Target which set to `Condition . == net472` will be hit and run firstly. Not sure whether .NET Framework related post build events will be hit before .NET/.NET Core post build events, but I hope this could give you some references. – Tianyu Aug 12 '21 at 08:39
  • Hi @Buzz, do you have any update? Please let me know if there is anything else that I can help here. – Tianyu Aug 18 '21 at 08:43
  • @Tianyu, thank you for exploring this. It sounds like you are also finding the existing conditionals to be insufficient to control the build order. A co-worker of mine mentioned a setting to control the number of parallel builds in VS. The idea being to limit it to 1. I haven't had a chance to look for it yet or see the behavior in multi-target projects. – Buzz Aug 19 '21 at 14:34
  • I think it’s Tools > Options > Projects and Solutions > Build And Run > “maximum number of parallel project builds” feature. But this is for project level, one project with multi-target framework may not work. – Tianyu Sep 07 '21 at 07:45

0 Answers0