4

I have a csproj file that I'm trying to build in both MonoDevelop (v5) and Visual Studio (v2015). As part of the build process, there is some source code that needs to be generated from another file before the compile.

Using Prebuild-events in Visual Studio (Project->Properties->Build Events->Pre-build event command line), I get the following in the csproj file:

Visual Studio 2015:

 <PropertyGroup>
    <PreBuildEvent>do_code_generation</PreBuildEvent>
 </PropertyGroup>

This works in both Visual Studio and MonoDevelop, and would be fine, but there seems to be no way to generate or manipulate Visual Studio-generated PreBuildEvent's in the MonoDevelop IDE. Sure, you could edit the csproj file by hand if using MonoDevelop, though that isn't ideal.

Interestingly, when I use the MonoDevelop GUI to create the "prebuild event" (Project->Options->Custom Commands->BeforeBuild), the resulting XML looks like this:

MonoDevelop:

  <CustomCommands>
    <CustomCommands>
      <Command type="BeforeBuild" command="do_code_generation" workingdir="${ProjectDir}" />
    </CustomCommands>
  </CustomCommands>

And completely fails to run in Visual Studio. Even trying a simple command such as "echo hi > C:\test.txt" doesn't result in the C:\test.txt file being created - it just doesn't seem to respect MonoDevelop's CustomCommands, unless I'm missing something.

To summarize, can I have a PreBuildEvent work in both Visual Studio and the MonoDevelop IDE and be able to be manipulated from each respective GUI? Either:

1) Figure out how to manipulate VS-Generated PreBuildEvents in MonoDevelop or;

2) Figure out why VS doesn't respect "CustomCommands" and if they can be manipulated in Visual Studio.

Tronman
  • 141
  • 1
  • wrt "it completely fails in VisualStudio" -> if that's the case, that is a MonoDevelop bug, please file it here: http://bugzilla.xamarin.com/ – knocte Jul 20 '16 at 13:19
  • Opened here: https://bugzilla.xamarin.com/show_bug.cgi?id=42698 – Tronman Jul 20 '16 at 20:25
  • thanks! w.r.t. the general question, I think it's better you create your MSBuild logic in external msbuild files (e.g. files with .Targets extension, like Microsoft does), and then link to that logic from the .csproj events – knocte Jul 21 '16 at 02:37
  • Interesting - I'll look into that. Thanks. – Tronman Jul 22 '16 at 11:41

0 Answers0