Custom MSBuild Task depends on compiled code but also generates code that is depended on
I'm attempting to generate a C# code file that constructs an object tree based on an XML file. The elements in the XML refer to Types that are defined in the project that is being compiled. The generated code needs to construct an object tree of Types that are found in the project that is being compiled. To further complicate things, the generated code needs to be compiled into the project that is being compiled, and is referred to by code in the current project that is being compiled.

I'm currently trying to do this with a custom MSBuild Task. This Task will be distributed to other developers for use in their own projects, so I cannot hard-code the available Types into the Task.

Here is some sample code to illustrate what I'm doing:

    // This is not generated
    public class SomeClass {

        public void DoSomething() {}

        public string SomeProperty { get; set; }
    }

**SomeClass** is a Type that is defined in non-generated code in the project. Here is the XML file that refers to **SomeClass** and populates the **SomeProperty** property:

    ... bunch of XML...
    <SomeClass SomeProperty="SomeValue" />
    ... bunch more XML...

**SomeOtherClass** has a non-generated partial declaration:

    // This is not generated
    public partial class SomeOtherClass {
    
        public void SomeMethod() {
            someField.DoSomething();
        }
    }

The Task creates a partial **SomeOtherClass** declaration:

    // This is generated
    public partial class SomeOtherClass {
        
        private SomeClass someField = new SomeClass() {
            SomeProperty = "SomeValue"
        };
    }

I think this looks a lot like what WPF would have to do for XAML files, and my usage is related (using XML to generate code which instantiates an object tree, based on types in the same project that is compiling). 

What would be the best approach to this problem? Should I be doing a multiple stage compile and consuming intermediate files in the Task? Should I attempt to build a temporary assembly separately within the Task without the generated code, then do reflection on the temporary assembly, then generate the code files, then allow the normal build process to continue?

Thanks for your input.

Custom MSBuild Task depends on compiled code but also generates code that is depended on
===

I'm attempting to generate a C# code file that constructs an object tree based on an XML file. The elements in the XML refer to Types that are defined in the project that is being compiled. The generated code needs to construct an object tree of Types that are found in the project that is being compiled. To further complicate things, the generated code needs to be compiled into the project that is being compiled, and is referred to by code in the current project that is being compiled.

I'm currently trying to do this with a custom MSBuild Task. This Task will be distributed to other developers for use in their own projects, so I cannot hard-code the available Types into the Task.

Here is some sample code to illustrate what I'm doing:

    // This is not generated
    public class SomeClass {

        public void DoSomething() {}

        public string SomeProperty { get; set; }
    }

**SomeClass** is a Type that is defined in non-generated code in the project. Here is the XML file that refers to **SomeClass** and populates the **SomeProperty** property:

    ... bunch of XML...
    <SomeClass SomeProperty="SomeValue" />
    ... bunch more XML...

**SomeOtherClass** has a non-generated partial declaration:

    // This is not generated
    public partial class SomeOtherClass {
    
        public void SomeMethod() {
            someField.DoSomething();
        }
    }

The Task creates a partial **SomeOtherClass** declaration:

    // This is generated
    public partial class SomeOtherClass {
        
        private SomeClass someField = new SomeClass() {
            SomeProperty = "SomeValue"
        };
    }

I think this looks a lot like what WPF would have to do for XAML files, and my usage is related (using XML to generate code which instantiates an object tree, based on types in the same project that is compiling). 

What would be the best approach to this problem? Should I be doing a multiple stage compile and consuming intermediate files in the Task? Should I attempt to build a temporary assembly separately within the Task without the generated code, then do reflection on the temporary assembly, then generate the code files, then allow the normal build process to continue?

Thanks for your input.
