3

I'm working on a project that will run as a pre-build step to check if certain conditions have changed in a project. If they have, it should clean the project to force it to be rebuilt.

I've discovered this thread for starting MSBuild from within C#: running msbuild programmatically

But unfortunately the documentation I could find for these classes is not very detailed. Does anyone know of a way to fire off MSBuild from a C# app with the purpose of cleaning another project?

Jonathan
  • 167
  • 10
  • 1
    First learn how to use [msbuild on the command line](https://msdn.microsoft.com/en-us/library/ms164311.aspx), then use `Process.Start()`. – gunr2171 Jan 18 '18 at 20:46
  • @gunr2171 The linked question states that we should avoid doing that and OP appears to want to use the official API. – Mike Cluck Jan 18 '18 at 20:49
  • I don't see what's wrong with using command line programs @MikeC. In the end the "official" c# sdk will use it. Sure, using the c# version _might_ be cleaner to read, but they can both do the same things just as well. Personal preference. – gunr2171 Jan 18 '18 at 20:52
  • In the linked answer, if you replace "Build" with "Clean" in the line where BuildRequestData is constructed, doesn't that suit your needs? – stijn Jan 19 '18 at 08:38
  • @Jonathan apart from the concrete question, can you share the "certain conditions?". There are ways in msbuild itself to mark things as inputs and manage incremental compilation so you don't have to create a program as pre-build step – Martin Ullrich Jan 19 '18 at 10:31
  • @stijn Yeah I tried that out before posting this and got nothing. No errors or anything, but it didn't clean the project. – Jonathan Jan 19 '18 at 15:38
  • @MartinUllrich So we have a Web project that we're trying to split into two separate products with the same core. We've been investigating using a shared project for the core that will be referenced by the two consuming projects. The problem is, shared projects don't work very well for web projects. Apparently msbuild doesn't consider embedded resources at all in the up to date check. So we're having trouble getting the consuming projects to update Views. So I'm trying to write something that checks the view files and cleans the consuming projects if they've changed. – Jonathan Jan 19 '18 at 15:40
  • At this point we're probably going to abandon this route and try something else though. If you have any ideas for a better way to accomplish this I'm all ears. – Jonathan Jan 19 '18 at 15:45
  • Why don't you use nuget packages to share reusable libraries? If these are two separate products, it looks natural for such case. – Vlad DX Feb 05 '18 at 23:55

0 Answers0