0

I have built a custom msbuild task that I use to convert 3D models in the format I use in my engine. However there are some optional behaviours that I would like to provide. For example allowing the user to choose whether to compute the tangent array or not, whether to reverse the winding order of the indices, etc.

In the actual UI where you select the Build action for each file, is it possible to define custom fields that would then be fed to the input parameters of the task? Such as a "Compute Tangents" dropbox where you can choose True or False?

If that is possible, how? Are there any alternatives besides defining multiple tasks? I.e. ConvertModelTask, ConvertModelComputeTangentTask, ConvertModelReverseIndicesTask, etc.

TheWanderer
  • 244
  • 2
  • 9

2 Answers2

0

Everything in a MsBuild Custom Task, has to have "settable properties" to drive behavior.

Option 1. Define an ENUM-esque to drive you behavior.

From memory, the MSBuild.ExtensionPack.tasks and MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadElementText" does this type of thing. The "TaskAction" is the enum-esque thing. I say "esque", because all you can do on the outside is set a string. and then in the code, convert the string to an internal enum.

See code here:

http://searchcode.com/codesearch/view/14325280

Option 2: You can still use OO on the tasks. Create a BaseTask (abstract) for shared logic), and then subclass it, and make the other class a subclass, and the msbuild task that you call.

SvnExport does this. SvnClient is the base class. And it has several subclasses.

See code here:

https://github.com/loresoft/msbuildtasks/blob/master/Source/MSBuild.Community.Tasks/Subversion/SvnExport.cs

granadaCoder
  • 26,328
  • 10
  • 113
  • 146
0

You can probably dive deep with EnvDTE or UITypeEditor but since you already have a custom task why not keep it simple with a basic WinForm?

namespace ClassLibrary1
{
    public class Class1 : Task
    {
        public bool ComputeTangents { set { _computeTangents = value; } }

        private bool? _computeTangents;

        public override bool Execute()
        {
            if (!_computeTangents.HasValue)
                using (var form1 = new Form1())
                {
                    form1.ShowDialog();
                    _computeTangents = form1.checkBox1.Checked;
                }

            Log.LogMessage("Compute Tangents: {0}", _computeTangents.Value);

            return !Log.HasLoggedErrors;
        }
    }
}
Ilya Kozhevnikov
  • 10,242
  • 4
  • 40
  • 70