Monday, May 21, 2012

More Custom Build Rule Hacking

I have tried to live with the broken build rule but its making a mess of my builds. I just don't have time to waste nursing each build by hand... AHHHHHHHHHHHH!

So the only thing for it is to fix the freakin build rule.

The symptoms are:

1) The  "Output Directory" property is not being correctly calculated by the build macro (?)  and passed to the command line string which is passed to the HelpNDoc compiler.  I can see this in the output.log.
The big problem is that within the property pages, the command line string seems to be being correctly calculated and looks good.  WTF?

My hypothesis is that the evil lies within the .target file as this seems to manage how the information from the property pages is passed to the build system.


Fiddling with the .XML file.

As a first step I am going to "experiment" with the .xml file just to see what happens.

It looks like some of the categories are not being clearly defined, so I will add a couple of them to see what happens and see how the change-reload-test cycle works.

Unload and Re-load project do not seem to reload the changes?
Unloading and Re-Loading the Solution does not seem to reload the changes?

Time for some serious breaking.

I removed the .xml, .targets, .props files from the project directory just to try to force a failure. Thankfully I got an error.

E:\_dev\PointLightLab4\src\HelpPrj\HelpPrj.vcxproj : error  : The imported project "E:\_dev\PointLightLab4\src\HelpPrj\HelpNDocRule.props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.  E:\_dev\PointLightLab4\src\HelpPrj\HelpPrj.vcxproj

So it looks like the .props file is the first to be loaded and parsed. Interesting. Lets add it back and try to reload the project.

Still failing with the same Error?  WTF?  Is it just a spurious error?  Its from an statement in the .vcxproj file... so perhaps I should have a look. 

Found it.  The project seemed to be using the backup copy of the build rule I had in another directory.  Weird that the path in the error was wrong.  It should have been "E:\_dev\PointLightLab4\src\HelpPrj\BuildRule\HelpNDocRule.props" as that as the path in the .vcxproj file. Yet another MS bug?

Ok, we are passed that error. Now the missing .targets file is being correctly detected.

Loading E:\_dev\PointLightLab4\src\HelpPrj\HelpPrj.vcxproj ...
E:\_dev\PointLightLab4\src\HelpPrj\HelpPrj.vcxproj : error  : The imported project "E:\_dev\PointLightLab4\src\HelpPrj\HelpNDocRule.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.  E:\_dev\PointLightLab4\src\HelpPrj\HelpPrj.vcxproj

Replace the .targets file and the project "Reloads" without errors.  I guess the .xml file only gets parsed when I try to open the Property Pages. So its not been missed yet.  Lets test that theory.

Nope.  The property pages work fine without the .xml file being present.  I guess its completely useless?  The properties are certainly being defined without it. 

So I think my hacking needs to focus on the .props and .targets files.

There is a mess of properties for the HelpNDoc build rule defined in the vcxproj file as well I notice. Which makes sense. 

Added a couple of lines to the .vcxproj file.
*.chm,*.pdf, *.html
    *.chm,*.pdf, *.html

As the extensions where only defined for the debug builds for some reason.

Interestingly, when I make changes to the .vcxproj file and have the property pages open in VS, it detects that the file has changed and offers the option to reload it.  Nice! Although the changes I made are not showing up... WTF?

I still cannot figure out where the definitions for the property pages are comming from.  The .xml file is not being loaded at all, so it has to be at some point in the load chain.  Time to backtrack.

It's not in the .sln file.
It's not in the .vcxproj.user file.  (Although that needs some additions for new platform targets I have added)
It's not in old user files.

Somewhere its being cached. Bastard!

Ok, remove everything, unload the solution, close Visual Studio... reopen VS, reload the solution and... TAfuckingDA the custom build stuff has disapeared.  Finally.

Now can I add the .xml file back in? Replace the .xml file in the project directory.

Unloading and Reloading the project does not pick up the settings again. Ok, cycle the whole solution... no joy.  Cycle the whole VS.... and they are back.  OK, so essentially, fucking with the .xml file requires a complete cycle of Visual Studio to see the changes.

Making Progress.

Now to get all the categories defined and named the way I like...

Ok, all the categories are correctly defined in the category section and I have removed the spaces from the names simply from habit.  They now have nice display names too.

So the 's seem pretty straight forward. They are defined in the .xml file, and their "name" attribute is referenced in the .props file with what look like default values. These default values are then over-ridden by any values in the .vcxproj file (in th tag) and additionally over-ridden for each build target /platform (in a tag), again simply by referencing the property names defined in the .xml file. 

First order of business is to explicity set the values in the in the .vcxproj file for all the build targets. 

Try building again...

I'm getting an error about the .props file cannot be imported again. with a line and col reference in from the .vcxproj file.  Ok, looks like I have accidentally imported the file again in the ImportGroups that I copied earlier... wonder why it was there in the first place? Anyway, fixed now.

Now looking at the logs in the intermediate directory... the command line is correct.
And in the output directory?...... WhoooT!  We have output files correctly targeted!

Now, the /silent flag is not acting correctly. Tweak the .vcxproj file and we have success.

Now moving on to improving the custom build rule for HelpNDoc....

Found this reference for the MSBuild Syntax.
http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx

And an overview of using and createing build files
http://msdn.microsoft.com/en-us/library/dd393574.aspx

Would have been nice to know where these were a while back...

It's only after you have figured out the answers, that you really understand how to ask the question.  Damit.

After some reading...here is the final resource.

As usual with forums, your milage will vary considerably....
http://social.msdn.microsoft.com/Forums/en-US/msbuild/threads



No comments:

Post a Comment