MSBuild Task for CliGenerator

Posts   
 
    
leoduran
User
Posts: 35
Joined: 25-Jun-2004
# Posted on: 31-Dec-2004 17:16:08   

I wrote a simple MSBuild Task using the source code for CliGenerator.

All of this was for a project we are working on that uses LLBLGen for a VS.Net 2005 solution. Instead of using the command line task in MSBuild, I thought it would be fun to create a custom msbuild task for CliGenerator.

However, there is one problem with it that needs to be resolved.

On line 66 of Engine.cs in the CliGenerator source code you pass configurationSettings as a parameter to the Generator class. (I'm assuming this file is in Generator core) the line looks like this...


_generatorProcess.Start(tasks, projectToGenerate, templateSet, configurationSettings);

The problem with this line is that when the CliGenerator task is run from within msbuild, it cannot find the app config file. The workaround was to create a config file for the msbuild exe file and put the required settings inside of it. I called the file msbuild.exe.config and after putting it into the .net framwork 2.xx folder the CliGenerator task inside of msbuild worked just fine.

If you could pass in two parameters into the _generatorProcess.Start(... ) method instead of passing the config file you wouldn't have to create a config file for msbuild.

Otis, Is it possible to add an overload for Generator.Start that accepted the Drivers and TaskPerformers locations via string parameters instead of passing an ApplicationConfiguraiton class?

Thank you,

Leo

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 31-Dec-2004 18:09:03   

You can also create a configuration object yourself, it's an ApplicationConfiguration object, which is located in the ApplicationCore assembly. You have to fill in 4 properties.

The database driver configs is perhaps a problematic one. Here's the code which loads the database driver configs (property of ApplicationConfiguration) :


/// <summary>
/// Loads all Database driver definitions. It will search all subfolders in databaseDriversRootFolder for driver.config files.
/// If a file is found, it is read and interpreted as a new driver definition. Every driver definition is stored in the hashtable
/// databaseDriverDefinitions
/// </summary>
private void LoadDatabaseDriverDefinitions()
{
    string driverRootPath = Path.Combine(Application.StartupPath, _databaseDriversRootFolder);

    // get all subfolders in driverRootPath folder
    string[] driverFolders = Directory.GetDirectories(driverRootPath);

    foreach(string driverFolder in driverFolders)
    {
        // check if there is a 'driver.config' file in the folder.
        string driverConfigFilename = driverFolder + "\\driver.config";
        if(File.Exists(driverConfigFilename))
        {
            // yes, load it in XML DOM
            XmlDocument driverConfigDOM = new XmlDocument();
            driverConfigDOM.Load(new XmlTextReader(driverConfigFilename));

            DatabaseDriverConfig driverConfigToAdd = LoadDatabaseDriverConfig(driverConfigDOM);
            driverConfigToAdd.FullDriverPath = driverFolder;
            driverConfigToAdd.FullPathFilename = driverFolder + "\\" + driverConfigToAdd.AssemblyFilename;
            _databaseDriverDefinitions.Add(driverConfigToAdd.DriverID, driverConfigToAdd);
        }
    }
}


/// <summary>
/// Loads the driver config stored in the XmlDocument passed in into a DatabaseDriverConfig object.
/// </summary>
/// <param name="driverConfigDOM">XML document containing the driver config</param>
/// <returns>DatabaseDriverConfig object</returns>
private DatabaseDriverConfig LoadDatabaseDriverConfig(XmlDocument driverConfigDOM)
{
    DatabaseDriverConfig newDefinition = new DatabaseDriverConfig();

    // if there are nodes, process them and store them in an DatabaseDriverConfig instance.
    XmlNode currentNode;
    XmlNode rootNode = driverConfigDOM.SelectSingleNode("/databaseDriver");

    // Name
    currentNode = rootNode.SelectSingleNode("name");
    newDefinition.Name = currentNode.InnerText;

    // assemblyFilename
    currentNode = rootNode.SelectSingleNode("assemblyFilename");
    newDefinition.AssemblyFilename = currentNode.InnerText;

    // namespace
    currentNode = rootNode.SelectSingleNode("namespace");
    newDefinition.Namespace = currentNode.InnerText;

    // className
    currentNode = rootNode.SelectSingleNode("className");
    newDefinition.ClassName = currentNode.InnerText;

    // className
    currentNode = rootNode.SelectSingleNode("driverID");
    newDefinition.DriverID = currentNode.InnerText;

    // DynamicQueryEngineNamespace
    currentNode = rootNode.SelectSingleNode("dynamicQueryEngineNamespace");
    newDefinition.DynamicQueryEngineNamespace = currentNode.InnerText;

    // TemplatesRootFolder
    currentNode = rootNode.SelectSingleNode("templatesRootFolder");
    newDefinition.TemplatesRootFolder = currentNode.InnerText;

    return newDefinition;
}

Frans Bouma | Lead developer LLBLGen Pro